amibar / SmartThreadPool

A .NET Thread Pool fully implemented in C# with many features
http://www.codeproject.com/Articles/7933/Smart-Thread-Pool
Microsoft Public License
507 stars 182 forks source link

Two threads get the same WorkItem #4

Closed jvogelsang closed 11 years ago

jvogelsang commented 11 years ago

I'm using the STP 2.2.1 in a server application. Today I had a problem that a work item has been processed by two threads simultaneously. In this a known issues?

When looking into the sourcecode I've notices the method

PriorityQueue.Dequeue ()

In this method there is a sequence

workItem = _queues[queueIndex].First.Value;
_queues[queueIndex].RemoveFirst();

For me it seems that these two actions are not atomic, and it might be that two threads got the same WorkItem. Is that possible?

jvogelsang commented 11 years ago

Hmm, seems that the method PriorityQuue.Dequeue() in the current version is protected by a lock in WorkItemsQueue.DequeueWorkItem. This Method has been changed from version 2.2.1 to 2.2.3. So I will use 2.2.3 an try if this issue still occures.