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

Unexpected rare SyncExceptions from Condition.wait

Moderators: kris

Posted: 01/07/10 07:28:28 Modified: 01/07/10 07:28:48

In a program under linux using tango.core.sync.Conditions very rarely I'm getting a SyncException? with the message "Unable to wait for condition". Looking at the code I see this can come from either the indefinite wait or time out wait. I added some logging so I could tell which method was throwing the error and what the actual return code was from the pthread function. So far in about an 18 hour run I have two errors thrown by Condition.wait(timeout) with the error from pthread_cond_timedwait being EINVAL(22). The code where it's being thrown just looks like:

    synchronized (lock)

I'm positive the condition isn't being used with another lock and as you can see the lock should be held when wait is called. From the pthread documentation it looks like the only other reason for EINVAL is if the time passed in is invalid. So my guess at this point is that adjTimespec in tango.core.sync.Config is running into a rare overflow that is causing a negative tv_nsec. I'll go ahead and add some more logging to try and check that but any other ideas would be welcome.

Author Message

Posted: 01/07/10 07:41:34 -- Modified: 01/07/10 07:52:22 by
Janzert -- Modified 2 Times

Ahh, should have done just a bit more before posting. Using the following test I can get the error within a few seconds usually.

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)

Extra logging shows that the error is caused by tv_nsec being 1_000_000_000. It looks like changing line 61 of tango/core/sync/Config.d to test for <= instead of < fixes this.

Posted: 01/07/10 16:37:00


Thanks for debugging this - could you please create a ticket?

Posted: 01/08/10 02:45:04

Filed with patch as ticket #1830.