[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/tests/runtime/System/Threading TestT
From: |
Thong Nguyen <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/tests/runtime/System/Threading TestThread.cs,1.1,1.2 |
Date: |
Mon, 07 Jul 2003 04:34:23 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/Threading
In directory subversions:/tmp/cvs-serv21607/tests/runtime/System/Threading
Modified Files:
TestThread.cs
Log Message:
Put locks around non-atomic increments in TestThreadStartJoin
Index: TestThread.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/Threading/TestThread.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** TestThread.cs 3 Jul 2003 22:23:22 -0000 1.1
--- TestThread.cs 7 Jul 2003 08:34:20 -0000 1.2
***************
*** 76,102 ****
}
! int flag = 0;
! bool failed = false;
private void StartJoinRun()
{
! flag += Convert.ToInt32(Thread.CurrentThread.Name);
Thread.Sleep(200);
}
public void TestStartJoin()
! {
if (!IsThreadingSupported)
{
return;
}
-
- int expected;
- Thread thread;
- Thread[] threads = new Thread[10];
flag = 0;
expected = 0;
for (int i = 0; i < 10; i++)
--- 76,118 ----
}
! volatile int flag = 0;
! volatile bool failed = false;
private void StartJoinRun()
{
! int x, f;
+ x = Convert.ToInt32(Thread.CurrentThread.Name);
+
+ // This makes sure the increment is atomic without
+ // using a monitor.
+
+ for (;;)
+ {
+ f = flag;
+
+ if (Interlocked.CompareExchange(ref flag, f + x, f) ==
f)
+ {
+ break;
+ }
+ }
+
Thread.Sleep(200);
}
public void TestStartJoin()
! {
! int expected;
! Thread thread;
! Thread[] threads;
!
if (!IsThreadingSupported)
{
return;
}
flag = 0;
expected = 0;
+ threads = new Thread[10];
for (int i = 0; i < 10; i++)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/tests/runtime/System/Threading TestThread.cs,1.1,1.2,
Thong Nguyen <address@hidden> <=