2 using System
.Threading
;
6 private static readonly ReaderWriterLockSlim rwl
= new ReaderWriterLockSlim(LockRecursionPolicy
.SupportsRecursion
);
8 private static int abort_count
= 0;
9 private const int num_iterations
= 10;
11 private static int Main(string[] args
)
13 for (int i
= 0; i
< num_iterations
; i
++) {
14 Console
.WriteLine("Next iter");
16 Barrier barrier
= new Barrier (3);
18 Thread reader
= new Thread (UseLockForRead
);
19 Thread writer
= new Thread (UseLockForWrite
);
20 reader
.Start (barrier
);
21 writer
.Start (barrier
);
23 barrier
.SignalAndWait ();
32 if (abort_count
!= (num_iterations
* 2)) {
33 Console
.WriteLine ("Only {0} aborts", abort_count
);
39 private static void UseLockForRead (object barrier
)
43 ((Barrier
)barrier
).SignalAndWait ();
59 } catch (ThreadAbortException
) {
60 Interlocked
.Increment (ref abort_count
);
64 private static void UseLockForWrite (object barrier
)
69 ((Barrier
)barrier
).SignalAndWait ();
85 } catch (ThreadAbortException
) {
86 Interlocked
.Increment (ref abort_count
);