Почему pthread_cond_timedwait использует 2 блокировки (condlock и mutex)?

1
9

Основные шаги pthread_cond_timedwait следующие:

Почему нужна блокировка cond, а не только блокировка mutex? То есть:

1. Acquire the mutex lock (before calling pthread_cond_timedwait).
2. Acquire the cond lock.
3. Release the mutex lock.
4. Modify the cond data.
5. Release the cond lock.
6. Execute futex_wait.
7. woken up by other thread.
8. Re-acquire the cond lock.
9. Compare the cond data to determine if the current thread was woken up normally or due to a timeout, and whether it needs to wait again.
10. Modify the cond data.
11. Release the cond lock.
12. Re-acquire the mutex lock.
13. Release the mutex lock (after calling pthread_cond_timedwait).
1. Acquire the mutex lock (before calling pthread_cond_timedwait).
2. Modify the cond data.
3. Release the mutex lock.
4. Execute futex_wait.
5. woken up by other thread.
6. Re-acquire the mutex lock.
7. Compare the cond data to determine if the current thread was woken up normally or due to a timeout, and whether it needs to wait again.
8. Modify the cond data.
9. Release the mutex lock (after calling pthread_cond_timedwait).
Силантий
Вопрос задан8 марта 2024 г.

1 Ответ

Ваш ответ

Загрузить файл.