Re: PTHREAD_MUTEX_INITIALIZER
- From: David Schwartz <davids@xxxxxxxxxxxxx>
- Date: Mon, 23 Jun 2008 06:53:05 -0700 (PDT)
On Jun 23, 6:16 am, Anthony Williams <anthony....@xxxxxxxxx> wrote:
If the initialization is not truly static, the library must take care
of that behind the scenes, so it must be thread-safe. Yes, your code
is "guaranteed" to work, except that pthread_mutex_lock can fail for a
reason internal to the implementation, so you need to check the return
value for failure.
I wouldn't bother. There's nothing sane you can do when
pthread_mutex_lock fails. This would likely be an indication of some
kind of memory corruption or fatal error condition. You can't do
anything sane if locking a mutex fails for no application-level
reason.
Do you want to log the error? Odds are the log is protected by a
mutex.
Do you want to call 'abort'? Guess what many 'abort' implementations
do first? (Hint: They don't want more than one thread trying to
'abort' at the same time.)
Of course, 'exit' has to manipulate the list of exit handlers. Guess
what that's protected by. And the same argument about flushing stdio.
What about '_exit'? Guess what, it usually calls 'abort'.
So if your argument is that pthreads standards-compliant code can't
assume that pthread_mutex_lock won't fail for some mysterious reason,
please tell me what pthreads standards-compliant functions you can
reasonably expect to work after such a failure. Good luck with that.
DS
.
- Follow-Ups:
- Re: PTHREAD_MUTEX_INITIALIZER
- From: Chris Thomasson
- Re: PTHREAD_MUTEX_INITIALIZER
- From: Anthony Williams
- Re: PTHREAD_MUTEX_INITIALIZER
- References:
- Re: PTHREAD_MUTEX_INITIALIZER
- From: Anthony Williams
- Re: PTHREAD_MUTEX_INITIALIZER
- Prev by Date: Re: PTHREAD_MUTEX_INITIALIZER
- Next by Date: Re: PTHREAD_MUTEX_INITIALIZER
- Previous by thread: Re: PTHREAD_MUTEX_INITIALIZER
- Next by thread: Re: PTHREAD_MUTEX_INITIALIZER
- Index(es):
Relevant Pages
|