Static and global object of one class (mutex ) is not getting
initialized before it is used. Its default constructor is not called,
On the other hand if i make it local it is working properly.
Why this is happening ?
The pthread mutexes are not class objects, and therefore do not have
default constructors, regardless of which language you are using them
from.
You must explicitly assign the mutex the value
PTHREAD_MUTEX_INITIALIZER, or you must explicitly call
pthread_mutex_init() on it before using it. The
PTHREAD_MUTEX_INITIALIZER was added to draft 5 of the standard, and
survived into draft 10, which became the final version.
Many systems are actually at draft 4 of the standard, and don't have
the value PTHREAD_MUTEX_INITIALIZER; if you are porting the code from
a draft 4 standard system, you will need to change mutex
initialization, and you will also need to change the arguments to
pthread_create (which used to take an address of a pointer argument,
but now takes a pointer argument).
Draft 4 systems include HPUX before version 11, OSF DCE, and SGI's IRIX.
The normal general way this is handled at compile time is actually to
use PTHREAD_MUTEX_INITIALIZER as a guard macro, e.g.:
#ifdef PTHREAD_MUTEX_INITIALIZER
/* draft 5 or later; more likely, a standard pthreads system */
...
#else
/* draft 4 or older non-standard pthreads system */
...
#endif
The OpenLDAP project tends to get this right (so does the MCSC C++
STL, and so does MySQL - not surprising, since I did the original
patches for all three of them).
The O'Reilly book dedicates a chapter to the differences ("Appendix B:
Pthreads Draft vs. the Final Standard").
Without seeing your code, I can't answer why the local variable is
working for you, since if you aren't explicitly initializing it,
either, then you'd most likely be getting stack garbage, and you'd
only have a 2 in 4 billion chance of it being exactly the right stack
garbage for it to work. So I'm guessing you initialize it.
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Unix-porting mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/unix-porting/email@hidden