File tree Expand file tree Collapse file tree 1 file changed +13
-27
lines changed
Lib/test/test_free_threading Expand file tree Collapse file tree 1 file changed +13
-27
lines changed Original file line number Diff line number Diff line change 6
6
from threading import Thread , Barrier
7
7
from random import shuffle , randint
8
8
9
- from test .support import threading_helper , Py_GIL_DISABLED
9
+ from test .support import threading_helper
10
10
from test import test_heapq
11
11
12
12
@@ -178,39 +178,25 @@ def heapreplace_max_func(max_heap, replace_items):
178
178
self .assertEqual (len (max_heap ), OBJECT_COUNT )
179
179
self .test_heapq .check_max_invariant (max_heap )
180
180
181
- @unittest .skipUnless (Py_GIL_DISABLED , 'only used to test under free-threaded build' )
182
181
def test_lock_free_list_read (self ):
183
182
n , n_threads = 1_000 , 10
184
183
l = []
185
184
barrier = Barrier (n_threads * 2 )
186
185
187
- def writer ():
186
+ def worker ():
187
+ x = barrier .n_waiting
188
188
barrier .wait ()
189
189
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 )
214
200
215
201
@staticmethod
216
202
def is_sorted_ascending (lst ):
You can’t perform that action at this time.
0 commit comments