Pthread_mutex_t init error

I am using xcode 2.4.1 for tiger. When I do below, everything is fine. 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 do not know why. However, if I do pthread_mutex_t mute = PTHREAD_MUTEX_INITIALIZER; It works great. Why?

-edit- I did not run away, but it looks like a compilation. What for? a?

  pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; mute = mutex; 
+4
source share
2 answers

PTHREAD_MUTEX_INITIALIZER - Permanent initializer, valid only during initialization. This is a macro that does not necessarily expand to an integral type.

Your mute=mutex; not valid, you should use instead:

 pthread_mutex_init(&mute, NULL); 

or if you dynamically allocate mutexes:

 m = malloc(sizeof(pthread_mutex_t))); pthread_mutex_init(m, NULL); 
+16
source
 mute = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; 

This is another solution to this error.

+1
source

All Articles