Bug 11454 – Race in core.thread unit test causing transient unit test failures

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P4
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-06T08:36:00Z
Last change time
2014-02-08T23:44:12Z
Assigned to
nobody
Creator
safety0ff.bugz

Comments

Comment #0 by safety0ff.bugz — 2013-11-06T08:36:54Z
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(); } --------------------------------------------
Comment #1 by safety0ff.bugz — 2014-02-08T23:44:12Z
Even though I created this report first, I'll mark this one as the duplicate. *** This issue has been marked as a duplicate of issue 11519 ***