1.初始化互斥量
pthread_mutex_t myMutex;
pthread_mutex_init(&myMutex, NULL);
2.互斥量的使用
pthread_mutex_lock(&myMutex);
// Enter the code you need to protect here
pthread_mutex_unlock(&myMutex);
3.销毁互斥锁
pthread_mutex_destroy(&myMutex);
pthread_mutex_t myMutex;
pthread_mutex_init(&myMutex, NULL);
pthread_mutex_lock(&myMutex);
// Enter the code you need to protect here
pthread_mutex_unlock(&myMutex);
pthread_mutex_destroy(&myMutex);
本文标题:Linux下同步机制——互斥量的使用
本文链接:https://www.haomeiwen.com/subject/zabuhctx.html
网友评论