File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ # test concurrent interning of strings
2+ #
3+ # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
4+
5+ import _thread
6+
7+ # function to check the interned string
8+ def check (s , val ):
9+ assert type (s ) == str
10+ assert int (s ) == val
11+
12+ # main thread function
13+ def th (base , n ):
14+ for i in range (n ):
15+ # this will intern the string and check it
16+ exec ("check('%u', %u)" % (base + i , base + i ))
17+
18+ with lock :
19+ global n_finished
20+ n_finished += 1
21+
22+ lock = _thread .allocate_lock ()
23+ n_thread = 4
24+ n_finished = 0
25+
26+ # spawn threads
27+ for i in range (n_thread ):
28+ _thread .start_new_thread (th , (i * 1000 , 1000 ))
29+
30+ # busy wait for threads to finish
31+ while n_finished < n_thread :
32+ pass
33+
34+ print ('pass' )
You can’t perform that action at this time.
0 commit comments