This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem w/ c++,threads,static initializers

Rasmus Hahn wrote:
Hi Thomas,

Problem solved: it was not the mutex but the but the pthread_mutexattr_t
that caused the error. cygwin's pthread_mutexattr_init () function checks
if its argument points to a valid object. If the pthread_mutexattr_t's value still points to a valid object (from a previous call)
pthread_mutexattr_init () fails, and so do later pthread_mutex_init()s with
this attribute. I think this behaviour is not correct since an uninitialized
pthread_mutexattr_t can point to anything (as a previously created attribute),
so this is probably a bug in cygwin (or what does the International Pthread
Attributes Committee say?). A quick look in winsup/cygwin/ shows
that this kind of check is done for more of the ..._init() functions, so there
may be similar effects (but i did not test that yet). Demo-Program below does
not work with (my) cygwin but does in my linux box:

#include <pthread.h>
int main () {
  pthread_mutexattr_t attr;
  pthread_mutexattr_init (&attr);
  if (pthread_mutexattr_init (&attr)) {
    printf ("error should not happen\n");

Have a look at

"Results are undefined if pthread_mutexattr_init() is called specifying an already initialized attr attributes object."

Unfortunately the spec does not specify EBUSY (which as returned at the moment) as a valid return code for pthread_mutexattr_init, therefore i will change all attr_init functions to simply return 0 if they are called with an already initialized attribute.


-- Unsubscribe info: Problem reports: Documentation: FAQ:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]