views:

58

answers:

1

pthread supports static initialization of pthread_mutex_t using PTHREAD_MUTEX_INITIALIZER.

Is it possible to achieve a similar static mechanism for mutex initialization using Windows mutex?

+1  A: 

No, since Windows mutex are handles, they must be initialized with CreateMutex().

Note that the static initialization of pthread_mutex_t using PTHREAD_MUTEX_INITIALIZER is not a real init, it will be done internally at the first call to pthread_mutex_lock() or pthread_mutex_trylock()

CharlesB
Yes. But, if I initialize a mutex using PTHREAD_MUTEX_INITIALIZER and two threads parallely call pthread_mutex_lock, will it lead to any problem?
Jay
Not sure, but since pthread_mutex_lock is thread-safe it should be OK
CharlesB