Make setMaxMailboxSize a property of a Tid?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Thu Nov 17 14:32:00 PST 2011
I've had this bug recently:
auto workTid = spawn(&work);
setMaxMailboxSize(thisTid, 1, OnCrowding.throwException);
IOW, I've passed 'thisTid' instead of 'workTid' to the call.
Is there any reason why had to be a global function? Tid has a private
MessageBox which has the setMaxMsgs method. We can't really call this
method directly via "tid.mbox.setMaxMsgs" since it's private, but a
forwarding function could be put inside of Tid:
struct Tid {
void setMaxMailboxSize( Tid tid, size_t messages, OnCrowding doThis )
{
final switch( doThis )
{
case OnCrowding.block:
return mbox.setMaxMsgs( messages, &onCrowdingBlock );
case OnCrowding.throwException:
return mbox.setMaxMsgs( messages, &onCrowdingThrow );
case OnCrowding.ignore:
return mbox.setMaxMsgs( messages, &onCrowdingIgnore );
}
}
// ...
}
Of course the global function would have to be kept for compatibility..
Btw, MessageBox is ddoc documented, but nothing outside of
std.concurrency can call any of its methods and the class itself is
private. That seems kind of strange.. If it's not intended to be
subclassed it could be marked with final as well, no?
Also, it would be cool if I could read the m_localMsgs field, just to
inspect if there are any messages left without doing a blocking call
or popping any messages off the queue.
More information about the Digitalmars-d-learn
mailing list