.net 4.0 parallel dictionary

I would like to use the new parallel collections in .NET 4.0 to solve the following problem.

The main data structure that I want to have is the turn of consumer producers, there will be one consumer and several manufacturers.

There are items like A, B, C, D, E that will be added to this queue. Elements of type A, B, C are added to the queue in the usual way and processed in order.

However, elements of type D or E can only exist in the queue zero or once. If one of them needs to be added, and another already exists of the same type that has not yet been processed, this should update this other place in the queue. After the update, the position of the queue will not change (that is, it will not return to the queue).

What .NET 4.0 classes are best suited for this?

+3
source share
1 answer

I think that there is no (priority) queue in .net 4 that would support the AddOrUpdate atomic operation. There is only a ConcurrentDictionary that supports this, but it is not suitable if you need to save an order.

So your option, perhaps, is to use some combination of the two.

However, keep in mind that you will lose the security of parallel structures as soon as you perform the joint operations on them; you must implement the locking mechanism yourself (see an example of such a situation here: .Net4 Gem: ConcurrentDictionary - tips and tricks ).

Google .

+3

Source: https://habr.com/ru/post/1747816/


All Articles