Hi, simple queue is problematic when accessing it from multiple threads and so i heard about ConcurrentQueue but it seems that it is not part of netmf 4.2, Is there any alternative for it?
Thanks
Hi, simple queue is problematic when accessing it from multiple threads and so i heard about ConcurrentQueue but it seems that it is not part of netmf 4.2, Is there any alternative for it?
Thanks
No. Just use locks to guard your array — that’s what ConcurrentQueue does internally, anyway…
This queue is being accessed by two threads, the first enqueue and the second dequeue.
The problem is that when the second threads dequeue the first one is locked, which means that the queue is sync and not asnyc, that’s my problem I need to solve
The .NET ConcurrentQueue does not use locks internally, it falls into a class of data structures know as a lock free data structure typically using memory barriers and compare and swap operations amongst others to eliminate the need to take a lock. Of course this is an implementation detail that could change.
Then they are much cooler than I initially thought!
8)
Guys, i need solution please
You have an answer, use a lock or implement a lock free data structure.
However, we might need to know more about your specific scenario that caused you to experience such high contention ie. every dequeue catches the queue while it is locked busy with an enqueue. Maybe you need a solution that provides a more fine grained locking solution, but to provide an effective solution would require a better understanding of what you are doing.