summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2023-10-20 16:51:34 (GMT)
committerGitHub <noreply@github.com>2023-10-20 16:51:34 (GMT)
commit264f4af506bf5b587105eab37fcfb7dfa62d6587 (patch)
tree80b5fb6aebebcd4aa97448d3955af952dad7e93e
parentcb4f7462d122d7ec9dd9d909014c548a0b945028 (diff)
downloadcpython-264f4af506bf5b587105eab37fcfb7dfa62d6587.zip
cpython-264f4af506bf5b587105eab37fcfb7dfa62d6587.tar.gz
cpython-264f4af506bf5b587105eab37fcfb7dfa62d6587.tar.bz2
gh-111119: Fix flaky test test_lock_two_threads (gh-111124)
-rw-r--r--Modules/_testinternalcapi/test_lock.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Modules/_testinternalcapi/test_lock.c b/Modules/_testinternalcapi/test_lock.c
index 33b49da..82a0c82 100644
--- a/Modules/_testinternalcapi/test_lock.c
+++ b/Modules/_testinternalcapi/test_lock.c
@@ -75,10 +75,18 @@ test_lock_two_threads(PyObject *self, PyObject *obj)
assert(test_data.m.v == 1);
PyThread_start_new_thread(lock_thread, &test_data);
- while (!_Py_atomic_load_int(&test_data.started)) {
- pysleep(10);
- }
- pysleep(10); // allow some time for the other thread to try to lock
+
+ // wait up to two seconds for the lock_thread to attempt to lock "m"
+ int iters = 0;
+ uint8_t v;
+ do {
+ pysleep(10); // allow some time for the other thread to try to lock
+ v = _Py_atomic_load_uint8_relaxed(&test_data.m.v);
+ assert(v == 1 || v == 3);
+ iters++;
+ } while (v != 3 && iters < 200);
+
+ // both the "locked" and the "has parked" bits should be set
assert(test_data.m.v == 3);
PyMutex_Unlock(&test_data.m);