@@ -412,9 +412,9 @@ static int test_pre_initialization_sys_options(void)
412412
413413
414414/* bpo-20891: Avoid race condition when initialising the GIL */ 
415- static  void  bpo20891_thread (void  * lockp )
415+ static  void  bpo20891_thread (void  * eventp )
416416{
417-     PyThread_type_lock   lock  =  * (( PyThread_type_lock * ) lockp ) ;
417+     PyEvent   * event  =  ( PyEvent   * ) eventp ;
418418
419419    PyGILState_STATE  state  =  PyGILState_Ensure ();
420420    if  (!PyGILState_Check ()) {
@@ -423,8 +423,7 @@ static void bpo20891_thread(void *lockp)
423423    }
424424
425425    PyGILState_Release (state );
426- 
427-     PyThread_release_lock (lock );
426+     _PyEvent_Notify (event );
428427}
429428
430429static  int  test_bpo20891 (void )
@@ -434,27 +433,17 @@ static int test_bpo20891(void)
434433
435434    /* bpo-20891: Calling PyGILState_Ensure in a non-Python thread must not 
436435       crash. */ 
437-     PyThread_type_lock  lock  =  PyThread_allocate_lock ();
438-     if  (!lock ) {
439-         error ("PyThread_allocate_lock failed!" );
440-         return  1 ;
441-     }
442436
443437    _testembed_Py_InitializeFromConfig ();
438+     PyEvent  event  =  {0 };
444439
445-     unsigned long  thrd  =  PyThread_start_new_thread (bpo20891_thread , & lock );
440+     unsigned long  thrd  =  PyThread_start_new_thread (bpo20891_thread , & event );
446441    if  (thrd  ==  PYTHREAD_INVALID_THREAD_ID ) {
447442        error ("PyThread_start_new_thread failed!" );
448443        return  1 ;
449444    }
450-     PyThread_acquire_lock (lock , WAIT_LOCK );
451- 
452-     Py_BEGIN_ALLOW_THREADS 
453-     /* wait until the thread exit */ 
454-     PyThread_acquire_lock (lock , WAIT_LOCK );
455-     Py_END_ALLOW_THREADS 
456445
457-     PyThread_free_lock ( lock );
446+     PyEvent_Wait ( & event );
458447
459448    Py_Finalize ();
460449
0 commit comments