Check to see if a pthread mutex is locked or unlocked (After a thread has locked itself)

后端 未结 3 1700
孤城傲影
孤城傲影 2020-11-29 06:54

I need to see if a mutex is locked or unlocked in an if statement so I check it like this...

if(mutex[id] != 2){
    /* do stuff */
}

but w

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 07:11

    You can't compare a pthread_mutex_t with a int.

    You can use

    int pthread_mutex_trylock(pthread_mutex_t *mutex);
    

    to check that.

提交回复
热议问题