Re: about destroying pthread mutex
- From: lmike <lmike3000@xxxxxxxxx>
- Date: Fri, 17 Jul 2009 07:33:15 -0700 (PDT)
On Jul 17, 3:02 am, David Schwartz <dav...@xxxxxxxxxxxxx> wrote:
On Jul 16, 8:21 pm, lmike <lmike3...@xxxxxxxxx> wrote:
First of all, if I don't destroy the mutex when the process goes down,
the mutex resource won't be released by OS, correct?
No, it won't. But it probably won't exist anymore either. On most
operating systems, a mutex is just a chunk of virtual memory in the
process' address space. Since the process' address space no longer
exists, neither does the mutex.
How do you guys destroy this mutex during normal process exit? -- do
it with atexit()?
After you have cleanly shutdown all the threads that could be using
the mutex, call pthread_mutex_destroy.
Do you destroy the mutex during abnormal shutdown? -- e.g. when
process goes down because of a signal, and try to destroy the mutex in
the signal handler? Can I release the mutex resource after the process
is down (something like running ipcrm on IPCs)?
Generally, you don't try to clean up on abnormal shutdown.
Thanks, DS. That helps.
- Prev by Date: Re: about destroying pthread mutex
- Next by Date: Knowing exec'ed
- Previous by thread: Re: about destroying pthread mutex
- Next by thread: Re: about destroying pthread mutex