【发布时间】:2017-11-16 03:47:43
【问题描述】:
在我的代码中,我使用 pthread_mutx_trylock() 来检查线程 1 是否已完成他的 工作并释放互斥锁?请让我知道它是否有效?
在线程 1 中:
pthread_mutex_lock(&sync_wait);
// Waiting for return type.
pthread_mutex_unlock(&sync_wait);
在线程 2 中:
while (pthread_mutex_trylock(&sync_wait) == 0) {
}; // Wait until other thread has lock
// Waiting till thread 1 sync wait lock has not released.
pthread_mutex_unlock(&sync_wait);
【问题讨论】:
-
在实际程序中,
// Waiting for return type.是其他代码,还是只是注释,加锁和解锁操作是相邻发生的?
标签: c multithreading pthreads