mutex lock destroy on APUE

Aug 18, 2011 at 6:03pm
1
2
3
4
5
6
7
8
9
10
11
12

struct foo*fp;

pthread_mutex_lock(&fp->lock);

if(--fp->count==0)
{
pthread_mutex_unlock(&fp->lock);
//if some other thread modified count, what will happen???
pthread_mutex_destroy(&fp->lock);
free(fp);
}


if some other thread modified count, what will happen???
Aug 19, 2011 at 4:29am
You mean after the unlock? Nothing. What's supposed to happen?
Although if another thread messes with an object that is about to get deleted, you might have a problem anyway.
Topic archived. No new replies allowed.