Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Conversation

Safety0ff
Copy link
Contributor

sema.notify();
semb.wait();

Thread.sleep(dur!"msecs"(48));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this is for? And the 48 magic number.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's there to provoke a race with thread_suspendAll, i.e. let the thread spend some time in the critical region to test that it can't be suspended.
I think 48.msecs is a bit excessive for a unit test. I tested it with 1.msecs and it will reliably assert when critical regions aren't respected in thread_suspendAll.

@Safety0ff
Copy link
Contributor Author

I've reset the sleep to 1ms. I wanted to run it at least once with the paranoid 48 ms setting.

MartinNowak added a commit that referenced this pull request Feb 28, 2014
Fix issue 11519 - race in core.thread unit test
@MartinNowak MartinNowak merged commit f5bd52d into dlang:master Feb 28, 2014
@MartinNowak
Copy link
Member

Thanks

@braddr
Copy link
Member

braddr commented Feb 28, 2014

Almost any case of using sleep in a test is doing something wrong. This might be an improvement, but it really should be engineered with appropriate interlock primitives and not on time. In many cases the right posix primitive is a barrier (not sure what that would be on windows).

@MartinNowak
Copy link
Member

Almost any case of using sleep in a test is doing something wrong. This might be an improvement, but it really should be engineered with appropriate interlock primitives and not on time. In many cases the right posix primitive is a barrier (not sure what that would be on windows).

We're testing that a thread in a critical region cannot be suspended. The alternative to sleeping would be to burn CPU cycles. Using a mutex/semaphore would result in a deadlock.

@Safety0ff Safety0ff deleted the fix11454 branch May 25, 2014 17:20
redstar added a commit to ldc-developers/druntime that referenced this pull request Oct 12, 2014
This is a backport of the relevant code from dlang/druntime@98215d6.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants