mirror of
https://github.com/dlang/phobos.git
synced 2025-05-07 19:49:36 +03:00
Merge pull request #1556 from dawgfoto/fixMessageBoxInit
enforce thisTid was called before calling receive
This commit is contained in:
commit
84156739db
1 changed files with 18 additions and 15 deletions
|
@ -190,21 +190,6 @@ private
|
|||
Tid owner;
|
||||
}
|
||||
|
||||
private shared bool firstInitialization = true;
|
||||
|
||||
static this()
|
||||
{
|
||||
// NOTE: Normally, mbox is initialized by spawn() or thisTid(). This
|
||||
// doesn't support the simple case of calling only receive() in main
|
||||
// however. To ensure that this works, initialize the main thread's
|
||||
// mbox field here only the first time this is run.
|
||||
if (firstInitialization)
|
||||
{
|
||||
mbox = new MessageBox;
|
||||
firstInitialization = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static ~this()
|
||||
{
|
||||
|
@ -639,6 +624,12 @@ private void _send(T...)( MsgType type, Tid tid, T vals )
|
|||
* ---
|
||||
*/
|
||||
void receive(T...)( T ops )
|
||||
in
|
||||
{
|
||||
assert(mbox !is null, "Cannot receive a message until a thread was spawned "
|
||||
"or thisTid was passed to a running thread.");
|
||||
}
|
||||
body
|
||||
{
|
||||
checkops( ops );
|
||||
mbox.get( ops );
|
||||
|
@ -715,6 +706,12 @@ private template receiveOnlyRet(T...)
|
|||
* ---
|
||||
*/
|
||||
receiveOnlyRet!(T) receiveOnly(T...)()
|
||||
in
|
||||
{
|
||||
assert(mbox !is null, "Cannot receive a message until a thread was spawned "
|
||||
"or thisTid was passed to a running thread.");
|
||||
}
|
||||
body
|
||||
{
|
||||
Tuple!(T) ret;
|
||||
|
||||
|
@ -776,6 +773,12 @@ unittest
|
|||
message and $(D false) if it timed out waiting for one.
|
||||
+/
|
||||
bool receiveTimeout(T...)( Duration duration, T ops )
|
||||
in
|
||||
{
|
||||
assert(mbox !is null, "Cannot receive a message until a thread was spawned "
|
||||
"or thisTid was passed to a running thread.");
|
||||
}
|
||||
body
|
||||
{
|
||||
checkops( ops );
|
||||
return mbox.get( duration, ops );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue