Skip to content Skip to sidebar Skip to footer

Android Ndk Problem Pthread_mutex_unlock Issue

I'm having an issue with pthread_mutex_unlock and my native activity NDK app. I've added logging messages to each mutex initialization, lock, lock success and unlock. My program

Solution 1:

I figured it out. The problem was in the initialization. Although this works on several other platforms, I really wasn't doing it right. If you use custom init you should new the mutex). New init looks like this:

#define InitializeCriticalSection(p) \
{ \
p = new pthread_mutex_t; \
LOGW("Initialize Mutex(%u)", p); \
pthread_mutexattr_t attr; \
pthread_mutexattr_init(&attr); \
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); \
int ii_p = pthread_mutex_init(p, &attr); \
pthread_mutexattr_destroy(&attr); \
LOGW("Initialize Mutex(%u) Returned %d", p, ii_p); \
}

Whew!

Post a Comment for "Android Ndk Problem Pthread_mutex_unlock Issue"