Repository navigation
Commit 146eedb
committed
gh-158336: Fix race in lock_tests test_set_and_clear
test_set_and_clear started N threads calling event.wait() and then slept
50 ms (wait_threads_blocked) before calling event.set() and event.clear().
If a thread only reached wait() after clear(), it saw the flag unset and
blocked for LONG_TIMEOUT, and Bunch.__exit__ gave up after SHORT_TIMEOUT.
This happened on CI in the TSan free-threading job.
Wait until all N threads are in the Condition's waiter list instead.
Condition.wait() appends the waiter while holding the lock, and
notify_all() releases every waiter in the list, so each of those threads
is guaranteed to be woken by set().
On a TSan free-threading debug build, pinned to 2 CPUs shared with 4
busy-looping processes, the test failed in 9 of 40 runs before this
change and 0 of 40 after.1 parent 7352b6a commit 146eedb
1 file changed
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
572 | 572 | | |
573 | 573 | | |
574 | 574 | | |
575 | | - | |
576 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
577 | 582 | | |
578 | 583 | | |
579 | 584 | | |
| |||
0 commit comments