I would initialize the pthread_mutex_t as part of the declaration but, since it is a data member of the Mutex class I am writing, it can't be initialized as part of the declaration. I tried initializing the pthread_mutex_t in the initializer list but still get one of the two errors:
Code:
error: expected primary-expression before '{' token
One is better than two but it still needs some work. I still think it has to do with the fact that PTHREAD_MUTEX_INITIALIZER is a preprocessor definition. When processed,
Code:
Mutex::Mutex()
: mutex(PTHREAD_MUTEX_INITIALIZER)
{
}
would work out to be
Code:
Mutex::Mutex()
: mutex({_PTHREAD_MUTEX_SIG_init, {0}})
{
}
I'm not familiar with expressions like that. Should that compile? If so, is there any reason why it wouldn't?
As a more immediate solution, I've decided to use pthread_mutexattr_init() instead but I would still be interested in hearing an explanation of PTHREAD_MUTEX_INITIALIZER - how it works and why it doesn't here.