Why is swapcontext behaving so badly?