December 2019
Intermediate to advanced
346 pages
9h 8m
English
In this example, we will create a producer and consumer scenario using queues that are defined in the System.Collections namespace. There will be multiple tasks that will attempt to read or write to a queue and we need to ensure that the reads and writes are atomic:
Queue<int> queue = new Queue<int>();for (int i = 0; i < 500; i++) { queue.Enqueue(i);}
int sum = 0;
Parallel.For(0, 500, (i) =>{ int localSum ...Read now
Unlock full access