File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Lib/test/test_free_threading Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 5
5
6
6
from ast import Or
7
7
from functools import partial
8
- from threading import Thread
8
+ from threading import Barrier , Thread
9
9
from unittest import TestCase
10
10
11
11
try :
@@ -142,6 +142,27 @@ def writer_func(l):
142
142
for ref in thread_list :
143
143
self .assertIsNone (ref ())
144
144
145
+ def test_racing_get_set_dict (self ):
146
+ """Races getting and setting a dict should be thread safe"""
147
+ THREAD_COUNT = 10
148
+ barrier = Barrier (THREAD_COUNT )
149
+ def work (d ):
150
+ barrier .wait ()
151
+ for _ in range (1000 ):
152
+ d [10 ] = 0
153
+ d .get (10 , None )
154
+ _ = d [10 ]
155
+
156
+ d = {}
157
+ worker_threads = []
158
+ for ii in range (THREAD_COUNT ):
159
+ worker_threads .append (Thread (target = work , args = [d ]))
160
+ for t in worker_threads :
161
+ t .start ()
162
+ for t in worker_threads :
163
+ t .join ()
164
+
165
+
145
166
def test_racing_set_object_dict (self ):
146
167
"""Races assigning to __dict__ should be thread safe"""
147
168
class C : pass
You can’t perform that action at this time.
0 commit comments