gpt4 book ai didi

c - 在哪里解锁pthread中的互斥量?

转载 作者:IT王子 更新时间:2023-10-29 00:54:17 25 4
gpt4 key购买 nike

从主线程锁定互斥量,然后从另一个线程释放是一个好习惯吗?

或者我是否应该确保一个线程可以一次完成所有工作?即:锁定和解锁

最佳答案

http://www.manpagez.com/man/3/pthread_mutex_unlock/

(同样来自 POSIX 规范站点:http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html)

If the current thread holds the lock on mutex, then the pthread_mutex_unlock() function unlocks mutex.

Calling pthread_mutex_unlock() with a mutex that the calling thread does not hold will result in undefined behavior.

关于c - 在哪里解锁pthread中的互斥量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7221209/

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