[3.13] gh-135641: Fix flaky test_capi.test_lock_two_threads test case (gh-135642) (gh-135688)

The mutex may have the `_Py_HAS_PARKED` bit set.
(cherry picked from commit 17ac3933c3)

Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-06-18 20:47:59 +02:00 committed by GitHub
parent dfe0e30c80
commit 3bfb7da3d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -57,7 +57,10 @@ lock_thread(void *arg)
_Py_atomic_store_int(&test_data->started, 1);
PyMutex_Lock(m);
assert(m->_bits == 1);
// gh-135641: in rare cases the lock may still have `_Py_HAS_PARKED` set
// (m->_bits == 3) due to bucket collisions in the parking lot hash table
// between this mutex and the `test_data.done` event.
assert(m->_bits == 1 || m->_bits == 3);
PyMutex_Unlock(m);
assert(m->_bits == 0);