@@ -379,9 +379,9 @@ static int test_pre_initialization_sys_options(void)
379
379
380
380
381
381
/* bpo-20891: Avoid race condition when initialising the GIL */
382
- static void bpo20891_thread (void * lockp )
382
+ static void bpo20891_thread (void * eventp )
383
383
{
384
- PyThread_type_lock lock = * (( PyThread_type_lock * ) lockp ) ;
384
+ PyEvent * event = ( PyEvent * ) eventp ;
385
385
386
386
PyGILState_STATE state = PyGILState_Ensure ();
387
387
if (!PyGILState_Check ()) {
@@ -390,8 +390,7 @@ static void bpo20891_thread(void *lockp)
390
390
}
391
391
392
392
PyGILState_Release (state );
393
-
394
- PyThread_release_lock (lock );
393
+ _PyEvent_Notify (event );
395
394
}
396
395
397
396
static int test_bpo20891 (void )
@@ -401,27 +400,16 @@ static int test_bpo20891(void)
401
400
402
401
/* bpo-20891: Calling PyGILState_Ensure in a non-Python thread must not
403
402
crash. */
404
- PyThread_type_lock lock = PyThread_allocate_lock ();
405
- if (!lock ) {
406
- error ("PyThread_allocate_lock failed!" );
407
- return 1 ;
408
- }
409
-
403
+ PyEvent event = {0 };
410
404
_testembed_initialize ();
411
405
412
- unsigned long thrd = PyThread_start_new_thread (bpo20891_thread , & lock );
406
+ unsigned long thrd = PyThread_start_new_thread (bpo20891_thread , & event );
413
407
if (thrd == PYTHREAD_INVALID_THREAD_ID ) {
414
408
error ("PyThread_start_new_thread failed!" );
415
409
return 1 ;
416
410
}
417
- PyThread_acquire_lock (lock , WAIT_LOCK );
418
411
419
- Py_BEGIN_ALLOW_THREADS
420
- /* wait until the thread exit */
421
- PyThread_acquire_lock (lock , WAIT_LOCK );
422
- Py_END_ALLOW_THREADS
423
-
424
- PyThread_free_lock (lock );
412
+ PyEvent_Wait (& event );
425
413
426
414
Py_Finalize ();
427
415
0 commit comments