gpt4 book ai didi

pthreads - pthread_cancel 在使用互斥锁和条件变量时

转载 作者:行者123 更新时间:2023-12-05 03:14:29 28 4
gpt4 key购买 nike

您好,我有一个关于取消使用互斥锁和条件变量的线程的问题。该线程已延迟取消类型。当我只使用函数pthread_mutex_lock/unlock 和pthread_cond_wait 时,一个取消请求到来时,线程的取消点只有pthread_cond_wait。它是否会锁定互斥锁?我不确定,如果线程总是离开互斥解锁。还是 pthread_mutex_lock/unlock 函数也是取消点?谢谢。

最佳答案

我怀疑我能比 the documentation 更好地表达这个:

A condition wait (whether timed or not) is a cancellation point. When the cancelability type of a thread is set to PTHREAD_CANCEL_DEFERRED, a side effect of acting upon a cancellation request while in a condition wait is that the mutex is (in effect) re-acquired before calling the first cancellation cleanup handler. The effect is as if the thread were unblocked, allowed to execute up to the point of returning from the call to pthread_cond_timedwait() or pthread_cond_wait(), but at that point notices the cancellation request and instead of returning to the caller of pthread_cond_timedwait() or pthread_cond_wait(), starts the thread cancellation activities, which includes calling cancellation cleanup handlers.

另外请确保您知道其他函数是 cancellation points

关于pthreads - pthread_cancel 在使用互斥锁和条件变量时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24340194/

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