File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change 55import doctest
66
77from test .support import import_helper
8- from unittest import TestCase , skipUnless
8+ from unittest import TestCase , skipUnless , skipIf
99from operator import itemgetter
1010
11+
1112py_heapq = import_helper .import_fresh_module ('heapq' , blocked = ['_heapq' ])
1213c_heapq = import_helper .import_fresh_module ('heapq' , fresh = ['_heapq' ])
1314
@@ -402,6 +403,36 @@ def __le__(self, other):
402403 self .assertEqual (hsort (data , LT ), target )
403404 self .assertRaises (TypeError , data , LE )
404405
406+ @skipIf (py_heapq , 'only used to test c_heapq' )
407+ def test_lock_free_list_read (self ):
408+ n = 1_000_000
409+ l = []
410+ def writer ():
411+ for i in range (n ):
412+ self .module .heappush (l , 1 )
413+ self .module .heappop (l )
414+
415+ def reader ():
416+ for i in range (n ):
417+ try :
418+ l [0 ]
419+ except IndexError :
420+ pass
421+
422+ import threading
423+ threads = []
424+ for _ in range (10 ):
425+ t1 = threading .Thread (target = writer )
426+ t2 = threading .Thread (target = reader )
427+ threads .append (t1 )
428+ threads .append (t2 )
429+ t1 .start ()
430+ t2 .start ()
431+
432+ for t in threads :
433+ t .join ()
434+
435+
405436
406437class TestHeapPython (TestHeap , TestCase ):
407438 module = py_heapq
You can’t perform that action at this time.
0 commit comments