This repository was archived by the owner on May 20, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 6
6
import_module )
7
7
from test .support .script_helper import assert_python_ok , make_script
8
8
9
+ import _atomic
9
10
import gc
10
11
import sys
11
12
import sysconfig
@@ -378,15 +379,15 @@ def sleeper_gen():
378
379
time .sleep (0.000001 )
379
380
380
381
class C (list ):
381
- # Appending to a list is atomic, which avoids the use of a lock.
382
- inits = []
383
- dels = []
382
+ inits = _atomic . int ()
383
+ dels = _atomic . int ()
384
+
384
385
def __init__ (self , alist ):
385
386
self [:] = alist
386
- C .inits .append ( None )
387
+ C .inits .add ( 1 )
387
388
def __del__ (self ):
388
389
# This __del__ is called by subtype_dealloc().
389
- C .dels .append ( None )
390
+ C .dels .add ( 1 )
390
391
# `g` will release the GIL when garbage-collected. This
391
392
# helps assert subtype_dealloc's behaviour when threads
392
393
# switch in the middle of it.
@@ -405,23 +406,23 @@ def make_nested():
405
406
406
407
def run_thread ():
407
408
"""Exercise make_nested() in a loop."""
408
- while not exit :
409
+ while exit . load () == 0 :
409
410
make_nested ()
410
411
411
412
old_switchinterval = sys .getswitchinterval ()
412
413
sys .setswitchinterval (1e-5 )
413
414
try :
414
- exit = []
415
+ exit = _atomic . int ()
415
416
threads = []
416
417
for i in range (N_THREADS ):
417
418
t = threading .Thread (target = run_thread )
418
419
threads .append (t )
419
- with start_threads (threads , lambda : exit .append (1 )):
420
+ with start_threads (threads , lambda : exit .store (1 )):
420
421
time .sleep (1.0 )
421
422
finally :
422
423
sys .setswitchinterval (old_switchinterval )
423
424
gc .collect ()
424
- self .assertEqual (len ( C .inits ), len ( C .dels ))
425
+ self .assertEqual (C .inits . load ( ), C .dels . load ( ))
425
426
426
427
def test_boom (self ):
427
428
class Boom :
You can’t perform that action at this time.
0 commit comments