468,272 Members | 2,070 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

dotnet multithreading message queues

Ok, I think I have an understanding of how to (or not to) implement a
thread safe message queue. There are several key elements, I will try
to be brief without too much code.

* Use the dotnet Queue collection.
* The nice thing about Queue is that it operates on object.
* Virtually anything can be __try_cast<>ed and posted to the queue (or
vice versa).
* Optional: use AutoResetEvent or ManualResetEvent to signal when next
element has been posted.
* Depending on your threads, this may be crucial to avoid runaway
* In other words, you can block on a WaitOne() event call until the
next element has arrived, at which time the event Set() is called.
* Having auto reset events means that much less work. It's a personal
preference in any event (pardon the pun! :-).
* Finally, it is essential to ensure that the queue is synchronized
using Queue::Synchronized() since likely the queue instance will be
shared between threads.
* In other words, calls to Post() and Pend() will likely occur from
two or more address spaces.
* Calls to the queue pend may check for count immediately and return
the first dequeued item it sees.
* Or they may sit on WaitOne() until the event has been signaled.
* Finally, the above virtues can all be wrapped in a tidy module for
usage among several apps.

Any feedback is welcome on the approach, or similar experience, or
even other advice.

Best regards,
Michael Powell
Nov 17 '05 #1
0 1239

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Aki Niimura | last post: by
reply views Thread by Markus Bauer | last post: by
4 posts views Thread by Tingo | last post: by
3 posts views Thread by Brian Keating | last post: by
5 posts views Thread by sarge | last post: by
2 posts views Thread by Rich | last post: by
2 posts views Thread by MR | last post: by
2 posts views Thread by DBC User | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.