Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1054 (closed defect: fixed)

Opened 4 months ago

Last modified 1 month ago

ReadWriteMutex unittest can fail

Reported by: fawzi Assigned to: sean
Priority: major Milestone: 0.99.8
Component: Core Functionality Version: trunk
Keywords: triage Cc:

Description

The ReadWriteMutex? unit test checks that threads are really running in parallel, but the threads do very little operations, so especially if the system is a little busy the threadshave basically no overlap, and the test fails.

A simple fix is to replace the simple yiealds by a loop of yields

@@ -413,7 +415,8 @@
                     if( ++numReaders > maxReaders )
                         maxReaders = numReaders;
                 }
-                Thread.yield();
+               for (int i=0;i<1000;i++)
+                   Thread.yield();
                 synchronized( synInfo )
                 {
                     --numReaders;
@@ -474,7 +481,8 @@
                         if( ++numWriters > maxWriters )
                             maxWriters = numWriters;
                     }
-                    Thread.yield();
+                   for (int i=0;i<1000;i++)
+                      Thread.yield();
                     synchronized( synInfo )
                     {
                         --numWriters;

waiting a finite time would be even better.

Change History

04/17/08 06:27:02 changed by fawzi

sorry I messed up the previous patch. Anyway the idea is the correct one: make the single yield a loop.

Here is the correct patch

@@ -413,7 +415,8 @@
                     if( ++numReaders > maxReaders )
                         maxReaders = numReaders;
                 }
-                Thread.yield();
+               for (int i=0;i<1000;i++)
+                   Thread.yield();
                 synchronized( synInfo )
                 {
                     --numReaders;
@@ -454,7 +460,8 @@
                         if( ++numReaders > maxReaders )
                             maxReaders = numReaders;
                     }
-                    Thread.yield();
+                   for (int j=0;j<1000;j++)
+                       Thread.yield();
                     synchronized( synInfo )
                     {
                         --numReaders;
@@ -474,7 +481,8 @@
                         if( ++numWriters > maxWriters )
                             maxWriters = numWriters;
                     }
-                    Thread.yield();
+                   for (int j=0;j<1000;j++)
+                      Thread.yield();
                     synchronized( synInfo )
                     {
                         --numWriters;

05/17/08 17:23:15 changed by larsivi

Verified to fail (most of the time after installing a composite manager) with both gdc and dmd on linux.

05/24/08 06:01:35 changed by larsivi

  • keywords set to triage.

07/10/08 07:01:37 changed by larsivi

  • milestone changed from 0.99.7 to 0.99.8.

07/25/08 23:43:05 changed by sean

  • status changed from new to closed.
  • resolution set to fixed.

(In [3809]) Changed Thread.yield() to Thread.sleep() in unit tests. This closes #1054