File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -339,26 +339,35 @@ public void TestThread()
339339 ) ;
340340 }
341341 int th_cnt = 100 ;
342+ int started = 0 , locked = 0 , unlocked = 0 ;
342343 for ( int i = 0 ; i < th_cnt ; i ++ )
343344 {
344345 ThreadPool . QueueUserWorkItem ( _ =>
345346 {
347+ Interlocked . Increment ( ref started ) ;
346348 using ( Py . GIL ( ) )
347349 {
350+ Interlocked . Decrement ( ref locked ) ;
348351 _ps . update ( ) ;
349352 }
353+ Interlocked . Increment ( ref unlocked ) ;
350354 } ) ;
351355 }
352356 //equivalent to Thread.Join, make the main thread join the GIL competition
353357 int cnt = 0 ;
354- while ( cnt != th_cnt )
358+ var stopwatch = System . Diagnostics . Stopwatch . StartNew ( ) ;
359+ while ( cnt != th_cnt && stopwatch . ElapsedMilliseconds < 15000 )
355360 {
356361 using ( Py . GIL ( ) )
357362 {
358363 cnt = ps . Get < int > ( "th_cnt" ) ;
359364 }
360365 Thread . Yield ( ) ;
361366 }
367+
368+ if ( stopwatch . ElapsedMilliseconds > 15000 )
369+ Assert . Fail ( $ "started: { started } locked: { locked } unlocked: { unlocked } cnt: { cnt } ") ;
370+
362371 using ( Py . GIL ( ) )
363372 {
364373 var result = ps . Get < int > ( "res" ) ;
You can’t perform that action at this time.
0 commit comments