2 using System
.Threading
;
5 const int num_threads
= 10;
6 static int aborted
= 0;
7 static Barrier barrier
= new Barrier (num_threads
+ 1);
9 public static void ThreadFunc (object lock_obj
)
12 barrier
.SignalAndWait ();
13 Monitor
.Enter (lock_obj
);
14 Monitor
.Exit (lock_obj
);
15 } catch (ThreadAbortException
) {
16 Interlocked
.Increment (ref aborted
);
21 public static int Main (string[] args
)
23 Thread
[] tarray
= new Thread
[num_threads
];
25 for (int i
= 0; i
< num_threads
; i
++) {
26 object lock_obj
= new object ();
27 Monitor
.Enter (lock_obj
);
28 tarray
[i
] = new Thread (new ParameterizedThreadStart (ThreadFunc
));
29 tarray
[i
].Start (lock_obj
);
32 barrier
.SignalAndWait ();
34 for (int i
= 0; i
< num_threads
; i
++)
37 for (int i
= 0; i
< num_threads
; i
++)
40 Console
.WriteLine ("Aborted {0}", aborted
);
41 if (aborted
!= num_threads
)