| Store | Cart

Re: [TCLCORE] CFV: TIP #435

From: Gustaf Neumann <neum...@wu.ac.at>
Mon, 03 Aug 2015 19:36:43 +0200
Am 03.08.15 um 18:53 schrieb Alexandre Ferrieux:
>     - call once and for all early in Tcl's init (like T_FE) > pthread_atfork(TclAtforkHandler)>     - let TclAtForkHandler be:>>           lock(&atfmutex);>           for(p=atflist;p;p=p->next) p();>           unlock(&atfmutex);>>      - of course a couple of convenience routine would allow to > add/remove callbacks to atflist any time, in a thread-safe way thanks > to atfmutex

the pthread_atfork() registers 3 functions (AtForkPrepare, AtForkParent, 
AtForkChild),
all of these make sense. Certainly, the callbacks can behave differently 
depending on
certain global variables (an execute registered functions etc.), but if 
one wants
to call arbitrary TclAPI-calls in these functions, one needs essentially 
a full lock of tcl

     Tcl_MutexLock(&notifierMutex);
     TclpMasterLock();
     TclpMutexLock();

One can't even call Tcl_MutexLock() safely in the registered callbacks 
without
the TclpMutexLock(). This was the reason i implemented a version of
tclUnixNotfy.c avoiding the Tcl_* interface at all (implementing locks
directly on the pthread_* interace, similar to the Mac OS X
variant tclMaxOSXNotfy.c). One reason for the need for the locks is
that the forked process is a copy of the parent with all its state,
including mutex variables, that might be already in the locked state.

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.

The other question is, why dos Tcl really need TclpMasterLock() and 
TclpMutexLock()
but that is another can of worms.

-g


------------------------------------------------------------------------------
_______________________________________________
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