https://d.puremagic.com/issues/show_bug.cgi?id=11454

           Summary: Race in core.thread unit test causing transient
                    failures
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: [email protected]
        ReportedBy: [email protected]


--- Comment #0 from safety0ff.bugz <[email protected]> 2013-11-06 
08:36:54 PST ---
The culprit code is from line 2637 of src/core/thread.d [1]
It caused a test failure in an unrelated pull request
(https://d.puremagic.com/test-results/pull.ghtml?projectid=1&runid=779542 ,)
the PR simply removed a no-op and should not have caused any non-failing tests
to begin failing.

My hypothesis is that Thread.sleep is used to yield the secondary thread, but
the secondary thread gets rescheduled before the main thread, causing the first
assertion to fail.

Two solutions I've come up with:
- If the compiler does not treat shared variables as a C compiler treats
"volatile" variables, then we can add a secondary semaphore ensuring the
assertion is executed prior to the secondary thread proceeding.
- Otherwise the assertion is redundant due to the semaphore and can be removed.

[1]
--------------------------------------------
unittest
{
    import core.sync.semaphore;

    shared bool inCriticalRegion;
    auto sem = new Semaphore();

    auto thr = new Thread(
    {
        thread_enterCriticalRegion();
        inCriticalRegion = true;
        sem.notify();
        Thread.sleep(dur!"msecs"(1));
        inCriticalRegion = false;
        thread_exitCriticalRegion();
    });
    thr.start();

    sem.wait();
    assert(inCriticalRegion);
    thread_suspendAll();
    assert(!inCriticalRegion);
    thread_resumeAll();
}
--------------------------------------------

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to