Tuesday, 6 August 2013

Multiple threads writing, one thread reading from queue, thread safety

Multiple threads writing, one thread reading from queue, thread safety

I've had little experience in the past with concurrent threading, so I
need a bit of help here.
Basically, what I have is a Queue (whether managed as a singleton by DI
frameworks or in a static object). I also have multiple threads that need
to write to that queue, however just one thread will ever dequeue.
Due to my slight lack of experience on thread safety, do I need to do
something specific to ensure that something doesn't accidentally go awry?
Considering one of the requirements is for the queued objects to be in the
exact order they were sent to the queueing class in the first place.
I presume that having to use ConcurrentQueue is a must? Or will I have to
start doing my own magic with queueing and locking?

No comments:

Post a Comment