LWN.net Logo

Actually fork does THAT for you...

Actually fork does THAT for you...

Posted Nov 15, 2011 3:39 UTC (Tue) by foom (subscriber, #14868)
In reply to: Actually fork does THAT for you... by khim
Parent article: libabc: a demonstration library for kernel developers

> You don't need to do that. After fork just one thread survives.

Sure, but cleaning up after whatever the other thread was doing at the instant of the fork is generally impossible. You either need to grab a lock (or similar) in your atfork prefork handler to force the other thread into a known quiescent state, or shut it down. But, you probably don't really want to do either one before a fork-exec, it's just a waste of time.

> If the whole machinery described in pthread_atfork does not look like something designed to give you countless problems then I'm not sure you must write libraries at all.

I think the only thing pthread_atfork is *really* useful for is to ensure that libc's malloc() will keep working after fork().


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds