| Store | Cart

Re: [TCLCORE] CFV: TIP #435

From: Alexandre Ferrieux <alex...@gmail.com>
Mon, 3 Aug 2015 21:15:01 +0200
On Mon, Aug 3, 2015 at 7:36 PM, Gustaf Neumann <neum...@wu.ac.at> wrote:

>> The bad thing is that the longer the fork() takes (i.e. the larger> the memory footprint is, etc.), the longer we have a> full lock of the tcl-threads (time gap between AtForkPrepare() and> AtForkChild()/> AtForkParent()). Therefore, not calling pthread_atfork() avoids this storm.>

OK, sorry for addressing only the superficial aspect (monotonic
pthread_atfork) rather than the deeper one (allowing "thick" and "thin"
forks from the same process).

In this context, I think the prime issue with pthread_atfork is that it is
process-wide, or thread-agnostic.
Hence, even if callback registration could be undone, juggling it in a
thread-safe way would still be a challenge.
So, what about instrumenting it to be thread-sensitive ? The idea is:

  - early:
pthread_atfork(ThreadAwareATF_Prepare,ThreadAwareATF_Parent,ThreadAwareATF_Child)

  /* these 3 handlers use pthread_self() as key into a *very* small
hashtable to decide what to do */


   - "thin fork": just call fork(). The above handlers find nothing for the
calling thread, and do nothing, quickly. The only temporarily lock a master
mutex protecting the hashtable.

   - "thick fork":
TclAtForkFromThisThread(AtForkPrepare,AtForkParent,AtForkChild) ; then
eventually call fork() (directly or not). This function stores an entry
into the hash table for pthread_self(), associating it with the 3 given
sub-callbacks, which are typically the Notifier-Cleanup machinery already
published by you and Joe.


With this:

  - very small overhead on [exec], since the registered atfork handler just
does a hashtable miss. No lock held between Prepare and Child. No linear
footprint dependency.

  - "thick fork" clients still have the complete expressivity of atfork
handlers.

-Alex

------------------------------------------------------------------------------

_______________________________________________
Tcl-Core mailing list
Tcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-core

Recent Messages in this Thread
Gustaf Neumann Aug 09, 2015 06:20 pm
Alexandre Ferrieux Aug 10, 2015 01:42 pm
Gustaf Neumann Aug 10, 2015 02:55 pm
Jan Nijtmans Aug 26, 2015 01:34 pm
Alexandre Ferrieux Aug 08, 2015 10:38 am
Gustaf Neumann Aug 08, 2015 08:33 am
Alexandre Ferrieux Aug 08, 2015 10:21 am
Alexandre Ferrieux Aug 06, 2015 06:20 pm
Gustaf Neumann Aug 07, 2015 08:37 am
Alexandre Ferrieux Aug 07, 2015 11:24 pm
Joe English Jul 27, 2015 07:39 pm
Gustaf Neumann Jul 28, 2015 10:38 pm
Gustaf Neumann Jul 31, 2015 10:16 pm
Massimo Manghi Aug 02, 2015 08:09 am
Alexandre Ferrieux Aug 03, 2015 10:03 am
Massimo Manghi Aug 03, 2015 01:16 pm
Gustaf Neumann Aug 03, 2015 04:34 pm
Alexandre Ferrieux Aug 03, 2015 04:53 pm
Gustaf Neumann Aug 03, 2015 05:36 pm
Alexandre Ferrieux Aug 03, 2015 07:15 pm
Gustaf Neumann Aug 04, 2015 11:08 am
Alexandre Ferrieux Aug 04, 2015 11:37 am
Gustaf Neumann Aug 04, 2015 12:23 pm
Alexandre Ferrieux Aug 04, 2015 04:36 pm
Massimo Manghi Aug 04, 2015 11:20 pm
Gustaf Neumann Aug 06, 2015 05:50 pm
Alexandre Ferrieux Aug 06, 2015 06:13 pm
Gustaf Neumann Aug 06, 2015 05:31 pm
Jan Nijtmans Aug 06, 2015 03:49 am
Gustaf Neumann Aug 07, 2015 06:47 pm
Donal K. Fellows Jul 26, 2015 11:09 am
bch Jul 27, 2015 07:46 pm
Messages in this thread