File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from threading import Thread, Barrier
77
from random import shuffle, randint
88

9-
from test.support import threading_helper, Py_GIL_DISABLED
9+
from test.support import threading_helper
1010
from test import test_heapq
1111

1212

@@ -178,39 +178,25 @@ def heapreplace_max_func(max_heap, replace_items):
178178
self.assertEqual(len(max_heap), OBJECT_COUNT)
179179
self.test_heapq.check_max_invariant(max_heap)
180180

181-
@unittest.skipUnless(Py_GIL_DISABLED, 'only used to test under free-threaded build')
182181
def test_lock_free_list_read(self):
183182
n, n_threads = 1_000, 10
184183
l = []
185184
barrier = Barrier(n_threads * 2)
186185

187-
def writer():
186+
def worker():
187+
x = barrier.n_waiting
188188
barrier.wait()
189189
for i in range(n):
190-
heapq.heappush(l, 1)
191-
heapq.heappop(l)
192-
193-
def reader():
194-
barrier.wait()
195-
for i in range(n):
196-
try:
197-
l[0]
198-
except IndexError:
199-
pass
200-
201-
import threading
202-
threads = []
203-
with threading_helper.catch_threading_exception() as cm:
204-
for _ in range(n_threads):
205-
t1 = threading.Thread(target=writer)
206-
t2 = threading.Thread(target=reader)
207-
threads.append(t1)
208-
threads.append(t2)
209-
t1.start()
210-
t2.start()
211-
212-
for t in threads:
213-
t.join()
190+
if x % 2:
191+
heapq.heappush(l, 1)
192+
heapq.heappop(l)
193+
else:
194+
try:
195+
l[0]
196+
except IndexError:
197+
pass
198+
199+
self.run_concurrently(worker, (), n_threads * 2)
214200

215201
@staticmethod
216202
def is_sorted_ascending(lst):

0 commit comments

Comments
 (0)