gpt4 book ai didi

c - 如何避免mutex_lock阻塞?

转载 作者:行者123 更新时间:2023-11-30 17:51:19 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com