Re: PTHREAD_MUTEX_INITIALIZER




Hallvard B Furuseth wrote:
[...]
Must it be a bug?

No. :-)

"In cases where default mutex attributes are appropriate, the macro
PTHREAD_MUTEX_INITIALIZER can be used to initialize mutexes that are
statically allocated. The effect shall be equivalent to dynamic
initialization by a call to pthread_mutex_init() with parameter attr
specified as NULL, except that no error checks are performed." The thing
is that many programs using PTHREAD_MUTEX_INITIALIZER may well exhibit
undefined behaviour without any application's bugs under the current
wording. It would be helpful if the standard would make it clear that
*initial* call to pthread_mutex_lock() for a PTHREAD_MUTEX_INITIALIZER'd
mutex shall fail for all the same reasons as pthread_mutex_init() (in
addition to the current pthread_mutex_lock() "shall fail" failure
modes)...

regards,
alexander.
.



Relevant Pages

  • Re: PTHREAD_MUTEX_INITIALIZER
    ... "In cases where default mutex attributes are appropriate, the macro ... PTHREAD_MUTEX_INITIALIZER can be used to initialize mutexes that are ... deliberately create a low memory situation (or are designed to operate ...
    (comp.programming.threads)
  • Re: Re : is variant-length array declaration standard compatible?
    ... WITH_MUTEX_LOCK { ... independent scope for the macro expansions. ... This behavior /completely/ violates the semantics of the block ... of the block structure, and it doesn't cause the compiler to barf if the ...
    (comp.lang.c)
  • Re: is variant-length array declaration standard compatible?
    ... > WITH_MUTEX_LOCK { ... > independent scope for the macro expansions. ... > unique variable names automatically in C), it doesn't violate the semantics ... > of the block structure, and it doesn't cause the compiler to barf if the ...
    (comp.lang.c)
  • Re: ufsstat - testers / feedback wanted!
    ... >>(And therefore I would have to protect it with a mutex or critical section) ... I'm not sure about it but I bet there are some macro for this kind of ... Jeremie Le Hen ... < jeremie at le-hen dot org>< ttz at chchile dot org> ...
    (freebsd-current)
  • Re: data protected not by mutexes but program logic
    ... Hallvard B Furuseth wrote: ... memory on the active processor, or only for variables protected by that ...
    (comp.programming.threads)