tech-userlevel archive

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

Re: ucontext

OK I have another question, is it safe to do the following with threads and 
ucontext in a multithreaded process:

I allocate some global data structures to keep track of threads, ids, ucontext 
structures, etc.

The main thread creates a few *detached* worker threads, which run and then 
call getcontext() to save their context in a global data structure. As soon as 
they save their context, threads call pthread_exit().

At a later time, another thread goes through the global data structure, loads 
each thread's ucontext with setcontext() and runs that thread where it left 

Is it safe to do the above with detached threads? When a thread calls 
getcontext() does it get a complete copy of its context, or does the context 
contain some pointers to the current thread's data. So that if this detached 
thread terminates and later another thread is created, the memory will be 
recycled and the previously saved context will point to memory now owned by 
the new thread??

Home | Main Index | Thread Index | Old Index