3 using System
.Threading
;
7 public static void Main ()
12 Thread t1
= Thread
.CurrentThread
;
14 Thread t2
= new Thread (() => {
16 int local_can_gc
= can_gc
;
17 if (local_can_gc
> 0 && Interlocked
.CompareExchange (ref can_gc
, local_can_gc
- 1, local_can_gc
) == local_can_gc
)
22 } catch (ThreadStateException
) {
33 for (int i
= 0; i
< 50 * 40 * 5; ++i
) {
34 Interlocked
.Increment (ref can_gc
);
35 Thread
.CurrentThread
.Suspend ();
36 if ((i
+ 1) % (50) == 0)
38 if ((i
+ 1) % (50 * 40) == 0)