File tree 1 file changed +6
-7
lines changed
1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -338,16 +338,16 @@ public void TestThread()
338
338
//add function to the scope
339
339
//can be call many times, more efficient than ast
340
340
ps . Exec (
341
- "import clr \n " +
342
- "from System.Threading import Thread \n " +
341
+ "import threading \n " +
342
+ "lock = threading.Lock() \n " +
343
343
"def update():\n " +
344
- " global res, th_cnt\n " +
344
+ " global res, th_cnt\n " +
345
+ " with lock:\n " +
345
346
" res += bb + 1\n " +
346
- " Thread.MemoryBarrier()\n " +
347
347
" th_cnt += 1\n "
348
348
) ;
349
349
}
350
- int th_cnt = 3 ;
350
+ int th_cnt = 100 ;
351
351
for ( int i = 0 ; i < th_cnt ; i ++ )
352
352
{
353
353
System . Threading . Thread th = new System . Threading . Thread ( ( ) =>
@@ -368,9 +368,8 @@ public void TestThread()
368
368
{
369
369
cnt = ps . Get < int > ( "th_cnt" ) ;
370
370
}
371
- Thread . Sleep ( 10 ) ;
371
+ Thread . Yield ( ) ;
372
372
}
373
- Thread . MemoryBarrier ( ) ;
374
373
using ( Py . GIL ( ) )
375
374
{
376
375
var result = ps . Get < int > ( "res" ) ;
You can’t perform that action at this time.
0 commit comments