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

Ticket #1830 (closed defect: fixed)

Opened 11 years ago

Last modified 11 years ago

SyncException from Condition.wait(period)

Reported by: Janzert Assigned to: kris
Priority: major Milestone: 0.99.9
Component: Tango Version: 0.99.8 Sean
Keywords: Cc:

Description

Calling Condition.wait(period) can very rarely cause a SyncException? to be thrown under posix systems. The following program will usually exhibit the problem after a bit of time.

import tango.core.sync.Condition;
import tango.core.sync.Mutex;

void main()
{
    auto m = new Mutex();
    auto c = new Condition(m);

    while (true)
    {
        synchronized (m)
        {
            c.wait(0.000001);
        }
    }
}

After investigating it seems the problem is that adjTimespec in tango/core/sync/Config.d allows a timespec.tv_nsec = 1_000_000_000 to be created. This is then rejected as invalid by the call to pthread_cond_timedwait. The fix seems to be changing a condition check from < to <=.

--- tango/core/sync/Config.d    2009-11-28 20:15:28 +0000
+++ tango/core/sync/Config.d    2010-01-07 07:50:04 +0000
@@ -58,7 +58,7 @@

             t.tv_sec  += cast(Secs) v;
             auto  ns   = cast(long)((v % 1.0) * SECS_TO_NANOS);
-            if( SECS_TO_NANOS - t.tv_nsec < ns )
+            if( SECS_TO_NANOS - t.tv_nsec <= ns )
             {
                 t.tv_sec += 1;
                 ns -= SECS_TO_NANOS;

Change History

01/12/10 05:27:24 changed by kris

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

(In [5288]) fixes #1830 :: SyncException? from Condition.wait(period)

Big thanks to Janzert for finding and resolving this