2010.01.21 - it's not polite to say to a thread 'fork you!'

recently, while working new ACARM version (aka ACARM-ng1)) i was investigating threads and how do they behave when fork() is called. i found a set of articles you might be interested in.

if you want to keep it short, the general idea is – don't mix them (see: quotation in the title of this article)! the only exception is when calling fork() from within multi-threaded application just to call exec() in the forked process (ex. just like system() call does). there is a pitfall however, one must be aware of. when forking and spawning new process one must remember about secure file descriptor handling. in short, when calling exec() open descriptors are moved to exec'ed application.

when talking about threads there is also interesting topic on how to handle signals in threads. article thread-specific data and signal handling in multi-threaded applications covers this, though its VERY old and many things are outdated right now. the idea is to run dedicated thread just to handle incoming signals (i.e. idle 99.9999% of the time). this has another advantage – it allows to use mutexes and other synchronization mechanisms, since you know that signal will be handled in a separate thread, that will not wait forever for mutex to release.

1)
no home page yet
blog/2010/2010.01.21.txt · Last modified: 2021/06/15 20:08 by 127.0.0.1
Back to top
Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0