Peeking concurrency messages

ikod geller.garry at gmail.com
Tue Jun 25 14:40:11 UTC 2019


On Sunday, 23 June 2019 at 16:25:58 UTC, Anonymouse wrote:
> On Sunday, 23 June 2019 at 13:59:38 UTC, Francesco Mecca wrote:
>> On Sunday, 23 June 2019 at 09:33:27 UTC, Anonymouse wrote:
>>> Concurrency messages are sent via std.concurrency's send and 
>>> receive functions. Receiving a message consumes it, in the 
>>> sense that receiving again will catch the next message. The 
>>> only way of telling whether there is one waiting is to 
>>> consume the first and commit to handling it. In other words, 
>>> there is currently no way of checking whether the message box 
>>> is empty; all the (thread ID Tid) member variables via which 
>>> you could tell are private to the std.concurrency module.
>>>
>>> [...]
>>
>> Can you explain your use case? Maybe there is an elegant 
>> solution without resorting to check if the mailbox is full.
>>
>> Otherwise you could try a PR
>
> TL;DR: I need to check for messages very often, and they each

Another possible design (sorry if you already considered it and 
threw it away) would be call select/poll/kqueue on server socket 
and on the socketpair which 'connects' threaded plugin with the 
main loop. Each time plugin have message it sends it over 
std.concurrency and then wakes up main loop sending single byte 
over socketpair. This slightly complicate design and adds sockets 
housekeeping, but it works.


More information about the Digitalmars-d mailing list