Summary: std.concurrency : Need the count of a thread's message
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos

--- Comment #0 from Andrej Mitrovic <> 2011-04-02 
11:38:04 PDT ---
Currently I know of no public function from std.concurrency which lets me know
if there are *any* messages left in a queue for a thread. My current workaround
for this is to have a shared counter, which I increment in my main thread, and
decrement in my work thread whenever there are 1 or more messages left in the

Having the message queue length known is useful in cases where a work function
is constantly being called via a timer function. The work function first checks
if the main thread has sent any commands via messages (for example "switch to
verbose mode"), and then proceeds to do its own work based on these commands.

Here's an example project:

Obviously there's some contention between the main thread and worker thread's
stdout, but never mind that. The key here is that I need a way of knowing if
there are any messages left in the queue. This example doesn't show a *useful*
showcase, but I do have an example of processing MIDI with a high-priority
thread which calls a function hundreds of times per second (adapted from

I've tried using receiveTimeout, but this can be very very tricky (unreliable)
with timers that call a function hundreds of times per second.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to