[all-commits] [llvm/llvm-project] 64fc3c: [libc++] Hold mutex lock while notify_all is calle...
Quuxplusone via All-commits
all-commits at lists.llvm.org
Wed Jan 11 14:01:46 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 64fc3cd55d586498dd21c5b3cfaa755793913772
https://github.com/llvm/llvm-project/commit/64fc3cd55d586498dd21c5b3cfaa755793913772
Author: Arthur O'Dwyer <arthur.j.odwyer at gmail.com>
Date: 2023-01-11 (Wed, 11 Jan 2023)
Changed paths:
M libcxx/docs/Status/Cxx2bIssues.csv
M libcxx/src/thread.cpp
M libcxx/test/std/thread/thread.condition/notify_all_at_thread_exit.pass.cpp
A libcxx/test/std/thread/thread.condition/notify_all_at_thread_exit_lwg3343.pass.cpp
Log Message:
-----------
[libc++] Hold mutex lock while notify_all is called at notify_all_at_thread_exit
Releasing the mutex before the call to notify_all is an optimization.
This optimization cannot be used here. The thread waiting on the
condition might destroy the associated resources — mutex + condition
variable — and the notifier thread will access an destroyed variable
— the condition variable. In fact, notify_all_at_thread_exit is meant
exactly to join on detached threads, and the waiting thread doesn't
expect for the notifier thread to access any further shared resources,
making this scenario very likely to happen. The waiting thread might
awake spuriously on the release of the mutex lock. The reorder is
necessary to prevent this race.
Further details can be found at https://cplusplus.github.io/LWG/issue3343.
Differential Revision: https://reviews.llvm.org/D105758
More information about the All-commits
mailing list