http://d.puremagic.com/issues/show_bug.cgi?id=5806

           Summary: std.concurrency : Need the count of a thread's message
                    queue
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nob...@puremagic.com
        ReportedBy: andrej.mitrov...@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrov...@gmail.com> 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
queue.

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:
http://dl.dropbox.com/u/9218759/threadCount.zip

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
PortMidi).

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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to