File tree 1 file changed +10
-1
lines changed
1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -339,26 +339,35 @@ public void TestThread()
339
339
) ;
340
340
}
341
341
int th_cnt = 100 ;
342
+ int started = 0 , locked = 0 , unlocked = 0 ;
342
343
for ( int i = 0 ; i < th_cnt ; i ++ )
343
344
{
344
345
ThreadPool . QueueUserWorkItem ( _ =>
345
346
{
347
+ Interlocked . Increment ( ref started ) ;
346
348
using ( Py . GIL ( ) )
347
349
{
350
+ Interlocked . Decrement ( ref locked ) ;
348
351
_ps . update ( ) ;
349
352
}
353
+ Interlocked . Increment ( ref unlocked ) ;
350
354
} ) ;
351
355
}
352
356
//equivalent to Thread.Join, make the main thread join the GIL competition
353
357
int cnt = 0 ;
354
- while ( cnt != th_cnt )
358
+ var stopwatch = System . Diagnostics . Stopwatch . StartNew ( ) ;
359
+ while ( cnt != th_cnt && stopwatch . ElapsedMilliseconds < 15000 )
355
360
{
356
361
using ( Py . GIL ( ) )
357
362
{
358
363
cnt = ps . Get < int > ( "th_cnt" ) ;
359
364
}
360
365
Thread . Yield ( ) ;
361
366
}
367
+
368
+ if ( stopwatch . ElapsedMilliseconds > 15000 )
369
+ Assert . Fail ( $ "started: { started } locked: { locked } unlocked: { unlocked } cnt: { cnt } ") ;
370
+
362
371
using ( Py . GIL ( ) )
363
372
{
364
373
var result = ps . Get < int > ( "res" ) ;
You can’t perform that action at this time.
0 commit comments