views:

391

answers:

1

I am using xcode 2.4.1 on tiger. When i do below everything is ok. when i do

pthread_mutex_t mute;
ImageMan()
{
 dibSize=0;
 mute  = PTHREAD_MUTEX_INITIALIZER;
}

I get these two errors

error: expected primary-expression before '{' token
error: expected `;' before '{' token

I dont know why. However if i do pthread_mutex_t mute = PTHREAD_MUTEX_INITIALIZER; it works fine. Why?

-edit- I havent ran it but this seems to compile. Why? huh?

 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 mute = mutex;
+3  A: 

PTHREAD_MUTEX_INITIALIZER is a constant initializer, valid when in initialization only. It is a macro that doesn't necessarily expand to an integral type.

Your mute=mutex; is invalid- instead you should use:

pthread_mutex_init(&mute, NULL);

or if you're allocating mutexes dynamically:

m = malloc(sizeof(pthread_mutex_t)));
pthread_mutex_init(m, NULL);
geocar