tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: ucontext



On Tuesday 15 December 2009 02:25:11 Antti Kantee wrote:

> You could simply try it out with a few-line program to be sure.
> But here's what I recall:
> 
> libpthread expects to find pthread_t for a thread at the top of a stack.
> makecontext() itself won't do anything, but when you swapcontext()
> or setcontext() to the new context, your stack will change to somewhere
> without a pthread_t at the top.  When the program hits e.g. a libc routine
> requiring locking, pthread_mutex is called (due to how libc mutexes are
> implemented) and boom happens.
> 

Hmm.. I think context swapping could be quite useful in multithreaded 
applications. Solaris implementation is MT safe according to their man page.

If pthread_t is the only issue, there is probably a way to copy it to to a new 
stack...


Home | Main Index | Thread Index | Old Index