By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

dotnet multithreading message queues

P: n/a
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
threads.
* 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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.