EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Creating Zombies with epicsThreadExitMain
From: Andrew Johnson <[email protected]>
To: Michael Abbott <[email protected]>
Cc: [email protected]
Date: Tue, 13 May 2008 11:01:52 -0500
Michael Abbott wrote:

Ah, I misunderstood that -- however, it's a red herring in the current case, as something is going horribly wrong on my machine when we do this.

Which thread library is your machine using — is it the old LinuxThreads or NPTL? According to man pthreads you can use this shell command to find out:
getconf GNU_LIBPTHREAD_VERSION


I need to dig a bit into the pthread specification, but I'm sure I remember that _exit() is supposed to kill *everything* stone cold dead without ceremony.

You are probably right. However since we don't actually call _exit() in this circumstance it doesn't really matter — th stuff about _exit() seems to have been a Red Herring I introduced by not looking at our implementation of epicsThreadExitMain() — sorry about that.


We do have code in libCom/osi/os/posix that calls pthread_cancel() on all our threads, thus any call to epicsExit() will result in all our threads voluntarily shutting down. We had to introduce the epicsExit() and epicsAtExit() API because Windows runs atexit() routines after unloading all DLLs, even when the routines are found in said DLLs...

What exactly does epicsThreadExitMain() do to try and close the top level thread without terminating the process? When I've had to do this in my own processes I've found it easiest to just created a semaphore and block on it.

It calls pthread_exit(0). This appears to be legal since the Posix description of pthread_exit() includes the following wording:
The process shall exit with an exit status of 0 after the last
thread has been terminated. The behavior shall be as if the
implementation called exit() with a zero argument at thread
termination time.
http://www.opengroup.org/onlinepubs/009695399/functions/pthread_exit.html


However we don't actually rely on the above behaviour ourselves. Once epicsThreadExitMain() has been used the proper way to actually close an IOC down is for one of the remaining threads to call epicsExit(), which shuts down the other threads and calls exit().

HTH,

- Andrew
--
Talk is cheap. Show me the code. -- Linus Torvalds

References:
Creating Zombies with epicsThreadExitMain Michael Abbott
Re: Creating Zombies with epicsThreadExitMain Michael Abbott
Re: Creating Zombies with epicsThreadExitMain Andrew Johnson
Re: Creating Zombies with epicsThreadExitMain Michael Abbott

Navigate by Date:
Prev: Re: Queensgate NPS3*** series piezo controller Kurt Goetze
Next: RTEMS building problems Eric Williams
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Creating Zombies with epicsThreadExitMain Michael Abbott
Next: RE: Creating Zombies with epicsThreadExitMain Pearson, MR (Matthew)
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Sep 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·