Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C# BlockingCollection's TryTakeFromAny guarantee sequential checking of BlockingCollection objects?

I have two blocking collections - one of higheer priority than the other. If I use TryTakeFromAny and specify the higher priority BlockingCollection first, is it guaranteed that the higher priority queue will be looked into first?

like image 843
Salil Avatar asked Oct 20 '14 18:10

Salil


People also ask

What is the main cause of hep C?

Hepatitis C is a liver infection caused by the hepatitis C virus (HCV). Hepatitis C is spread through contact with blood from an infected person. Today, most people become infected with the hepatitis C virus by sharing needles or other equipment used to prepare and inject drugs.

Does hep C go away?

Overview. Hepatitis C virus (HCV) causes both acute and chronic infection. Acute HCV infections are usually asymptomatic and most do not lead to a life-threatening disease. Around 30% (15–45%) of infected persons spontaneously clear the virus within 6 months of infection without any treatment.

What does hep C pain feel like?

Many people with chronic HCV suffer from aches and pains in their joints. A variety of different joints can be involved but the most common are in the hands and wrists. These pains are often minor but occasionally the pain can be quite severe. In such cases painkillers can be used to relieve the symptoms.

How easy is it to get hep C?

Hepatitis C is spread only through exposure to an infected person's blood. High-risk activities include: Sharing drug use equipment. Anything involved with injecting street drugs, from syringes, to needles, to tourniquets, can have small amounts of blood on it that can transmit hepatitis C.


1 Answers

This isn't documented, so I would say there is no guarantee that it won't change in the future. Relying on it long term is probably not recommended. However, currently, BlockingCollection<T>.TryTakeFromAny does a quick check by looping through all the collections by index checking for an item (it checks if Count > 0 and then does TryTake). If no items are found it gets an internal wait handle for each collection and passes them to WaitHandle.WaitAny. This provides the guarantee:

This method returns when any handle is signaled. If more than one object becomes signaled during the call, the return value is the array index of the signaled object with the smallest index value of all the signaled objects.

So the current implementation would indeed behave as requested. If two collections get an item simultaneously, the lower index one would get taken.

like image 114
Mike Zboray Avatar answered Oct 07 '22 07:10

Mike Zboray