File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed
Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -338,16 +338,16 @@ public void TestThread()
338338 //add function to the scope
339339 //can be call many times, more efficient than ast
340340 ps . Exec (
341- "import clr \n " +
342- "from System.Threading import Thread \n " +
341+ "import threading \n " +
342+ "lock = threading.Lock() \n " +
343343 "def update():\n " +
344- " global res, th_cnt\n " +
344+ " global res, th_cnt\n " +
345+ " with lock:\n " +
345346 " res += bb + 1\n " +
346- " Thread.MemoryBarrier()\n " +
347347 " th_cnt += 1\n "
348348 ) ;
349349 }
350- int th_cnt = 3 ;
350+ int th_cnt = 100 ;
351351 for ( int i = 0 ; i < th_cnt ; i ++ )
352352 {
353353 System . Threading . Thread th = new System . Threading . Thread ( ( ) =>
@@ -368,9 +368,8 @@ public void TestThread()
368368 {
369369 cnt = ps . Get < int > ( "th_cnt" ) ;
370370 }
371- Thread . Sleep ( 10 ) ;
371+ Thread . Yield ( ) ;
372372 }
373- Thread . MemoryBarrier ( ) ;
374373 using ( Py . GIL ( ) )
375374 {
376375 var result = ps . Get < int > ( "res" ) ;
You can’t perform that action at this time.
0 commit comments