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 55
66from ast import Or
77from functools import partial
8- from threading import Thread
8+ from threading import Barrier , Thread
99from unittest import TestCase
1010
1111try :
@@ -142,6 +142,27 @@ def writer_func(l):
142142 for ref in thread_list :
143143 self .assertIsNone (ref ())
144144
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+
145166 def test_racing_set_object_dict (self ):
146167 """Races assigning to __dict__ should be thread safe"""
147168 class C : pass
You can’t perform that action at this time.
0 commit comments