[M3devel] pthread_atfork with user threads?
Jay K
jay.krell at cornell.edu
Sat Mar 20 09:48:05 CET 2010
Or should the userthreads version implement
itself and require user to call RTProcess.Fork()?
You know, we have this odd but ok/useful state:
Even though we support userthreads, every system
has pthreads. I still have to verify that all systems
have pthread_atfork, but I assume so.
Also funny thing btw, pthreads, userthreads, win32 threads,
the code will be highly shared.
They will call RegisterForkHandlers.
The fork handlers will be same or similar.
Specifically in ThreadPThread.c and ThreadPosix.c -- reinitialize.
For ThreadPosix that should achieve "don't switch to any preexisting thread",
which is equivalent to "kill all other threads".
implied question:
Call it AtFork or RegisterForkHandlers or ?
RTProcessC.c
typedef void (*ForkHandler)(void);
#ifndef _WIN32
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#endif
/* NOTE: Even userthreads now depends
* on availability of pthreads.
* This can be fixed if need be.
*/
int
RTProcess__RegisterForkHandlers(
ForkHandler prepare,
ForkHandler parent,
ForkHandler child)
{
#ifdef _WIN32
return 0;
#else
while (1)
{
int i = pthread_atfork(prepare, parent, child);
if (i != EAGAIN)
return i;
sleep(0);
}
#endif
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100320/02967e26/attachment-0001.html>
More information about the M3devel
mailing list