c - 如何避免mutex_lock阻塞?

标签 c multithreading pthreads

我想在 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/

相关文章:

java - 为什么在连接前两个对象后从多个对象创建字符串失败

linux - Linux 上的 munmap 性能

C - 系统调用 - 64 位 - 指针

c - 如何防止scanf导致C语言缓冲区溢出?

c++ - 从libuv句柄继承

multithreading - 发出信号量必须是原子的。 Pintos的sema_down安全吗?

c++ - 并行插入排序、幼稚尝试、使用 pthread 尝试失败、线程未并行排序,但与串行一起工作正常

c - 多线程 pthread 错误

c - 多线程光线追踪

c - 如何将给定级别的二叉搜索树转换为链接链?