File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Modules/_testinternalcapi Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -75,10 +75,18 @@ test_lock_two_threads(PyObject *self, PyObject *obj)
7575 assert (test_data .m .v == 1 );
7676
7777 PyThread_start_new_thread (lock_thread , & test_data );
78- while (!_Py_atomic_load_int (& test_data .started )) {
79- pysleep (10 );
80- }
81- pysleep (10 ); // allow some time for the other thread to try to lock
78+
79+ // wait up to two seconds for the lock_thread to attempt to lock "m"
80+ int iters = 0 ;
81+ uint8_t v ;
82+ do {
83+ pysleep (10 ); // allow some time for the other thread to try to lock
84+ v = _Py_atomic_load_uint8_relaxed (& test_data .m .v );
85+ assert (v == 1 || v == 3 );
86+ iters ++ ;
87+ } while (v != 3 && iters < 200 );
88+
89+ // both the "locked" and the "has parked" bits should be set
8290 assert (test_data .m .v == 3 );
8391
8492 PyMutex_Unlock (& test_data .m );
You can’t perform that action at this time.
0 commit comments