我想在 C 中使用带有 pthread 的线程。
我关于线程的一个问题是,当整个应用程序中继一个共享资源时,为什么互斥锁不会阻止执行?
博多
最佳答案
您需要 pthread_mutex_trylock()
函数。
The pthread_mutex_trylock() function shall be equivalent to pthread_mutex_lock(), except that if the mutex object referenced by mutex is currently locked (by any thread, including the current thread), the call shall return immediately.
引用:https://computing.llnl.gov/tutorials/pthreads/man/pthread_mutex_trylock.txt
关于c - 如何避免mutex_lock阻塞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16786321/