Re: ucontext switch problem
Re: ucontext switch problem
- Subject: Re: ucontext switch problem
- From: Chris Suter <email@hidden>
- Date: Sat, 19 Dec 2009 07:20:07 +1100
Hi Roger,
On Thu, Dec 17, 2009 at 9:56 PM, Roger Pau Monné <email@hidden> wrote:
> Thanks for the reply, it was very helpful. Now I'm having a problem with the
> returning context of swapcontext. I've made something like a user-space
> thread library, and all the context of the threads return to the same main
> context (all uc_link point to the same ucontext_t), but it seems that only
> the first one to end is able to switch the context correctly, the next one
> reports a "Bus Error". This only happens when I use a signal handler to
> change contexts, so I'm guessing there's something wrong there, but I'm not
> able to debug it. Also, this program works on Linux, I've attached the
> source, if anyone could take a look, I've been trying to get it to work on
> Mac OS X for some days without any luck or progress.
The problem is that after the first thread has finished you’re
switching to kernel_context and returning to your main function.
Later, when another thread terminates, you’re attempting to switch to
an out of date context—it points to the same stack but the stack has
changed. If it works on Linux, you’ve been lucky—if you were to zero
out the stack in your main function after returning, you’d see the
same crash on Linux.
I trust you’re doing this for purely academic interest since you’ll
encounter all kinds of problems with the runtime library (which uses
pthreads for its locking).
Kind regards,
Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden