2 using System
.Threading
;
4 internal class SpinLockWrapper
6 public SpinLock Lock
= new SpinLock (false);
11 public static void Main (string[] args
)
15 iterations
= Int32
.Parse (args
[0]);
17 ParallelTestHelper
.Repeat (delegate {
20 SpinLockWrapper wrapper
= new SpinLockWrapper ();
22 ParallelTestHelper
.ParallelStressTest (wrapper
, delegate {
24 wrapper
.Lock
.Enter (ref taken
);
25 int current
= currentCount
++;
29 SpinWait sw
= new SpinWait ();
30 for (int i
= 0; i
< 200; i
++)
44 static class ParallelTestHelper
46 public static void Repeat (Action action
, int numRun
)
48 for (int i
= 0; i
< numRun
; i
++) {
49 //Console.WriteLine ("Run " + i.ToString ());
54 public static void ParallelStressTest
<TSource
>(TSource obj
, Action
<TSource
> action
, int numThread
)
56 Thread
[] threads
= new Thread
[numThread
];
57 for (int i
= 0; i
< numThread
; i
++) {
58 threads
[i
] = new Thread(new ThreadStart(delegate { action(obj); }
));
62 // Wait for the completion
63 for (int i
= 0; i
< numThread
; i
++)