concurrent-queue

Parallel.For items in a List by using ConcurrentQueue - will this work?

自作多情 提交于 2020-01-05 19:20:42
问题 I have a List<TaskClass> TaskList items that we can iterate over using a Parallel loop. The items in the list are sorted in a particular order as the TaskClass implements IComparable with its own CompareTo(object obj) method. Thus we need the items acted upon in sequential order. Note they do NOT have to complete in sequential order, just start in sequential. Thus TaskList[0] should be started first; then TaskList[1], TaskList[2], ... However, we don't care if TaskList[2] completes first, or

Why weird behavior of concurrent queue?

痴心易碎 提交于 2019-12-31 03:17:06
问题 I am trying to understanding the concurrent queue of iOS GCD. The I made some code to test it, but found something weird. code as below: _syncQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0); for (int index = 0; index < 3; ++index) { dispatch_sync(_syncQueue, ^{ NSLog(@"sync@@@@@@ >>>> %d ",index); sleep(1); NSLog(@"sync@@@@@@ <<<< %d ",index); }); } for (int index = 3; index < 6; ++index) { dispatch_async(_syncQueue, ^{ NSLog(@"sync===== >>>> %d ",index); sleep(1); NSLog(@

ConcurrentQueue .Net: Multithreaded consumer

时光怂恿深爱的人放手 提交于 2019-12-10 18:14:45
问题 I had a very basic question which is more around concepts of ConcurrentQueue . A queue is FIFO. When multiple threads start accessing it, how do we guarantee FIFO? Suppose, I have added Apple , Oranges , Lemon , Peach and Apricot - in that order. The first TryTake should return Apple . But what happens when multiple threads starts giving their own TryTake requests? Would'nt there be a possibility that when one thread could return Lemon even before another thread could return Apple ? I am

RxJS parallel queue with concurrent workers?

╄→гoц情女王★ 提交于 2019-12-09 03:25:22
问题 Let's say I want to I download 10,000 files. I can easily build a queue of those 10,000 files (happy to take advice if any of this can be done better), import request from 'request-promise-native'; import {from} from 'rxjs'; let reqs = []; for ( let i = 0; i < 10000; i++ ) { reqs.push( from(request(`http://bleh.com/${i}`)) ) }; Now I have an array of Rx.JS observable I've created from promises that represent my queue. Now for the behavior of what I want, I want to issue Three-concurrent

ConcurrentQueue with multithreading

≡放荡痞女 提交于 2019-12-02 03:29:24
I am new to multi threading concepts. I need to add certain number of strings to a queue and process them with multiple threads. Using ConcurrentQueue which is thread safe. This is what I have tried. But all the items added into concurrent queue are not processed. only first 4 items are processed. class Program { ConcurrentQueue<string> iQ = new ConcurrentQueue<string>(); static void Main(string[] args) { new Program().run(); } void run() { int threadCount = 4; Task[] workers = new Task[threadCount]; for (int i = 0; i < threadCount; ++i) { int workerId = i; Task task = new Task(() => worker

Is it safe to put TryDequeue in a while loop?

痞子三分冷 提交于 2019-12-01 13:52:38
问题 I have not used concurrent queue before. Is it OK to use TryDequeue as below, in a while loop? Could this not get stuck forever? var cq = new ConcurrentQueue<string>(); cq.Enqueue("test"); string retValue; while(!cq.TryDequeue(out retValue)) { // Maybe sleep? } //Do rest of code 回答1: Yes it is safe as per the documentation, but it is not a recommended design. It might get "Stuck forever" if the queue was empty at the first call TryDequeue, and if no other thread pushes data in the queue after

RxJS parallel queue with concurrent workers?

梦想的初衷 提交于 2019-12-01 12:53:22
Let's say I want to I download 10,000 files. I can easily build a queue of those 10,000 files (happy to take advice if any of this can be done better), import request from 'request-promise-native'; import {from} from 'rxjs'; let reqs = []; for ( let i = 0; i < 10000; i++ ) { reqs.push( from(request(`http://bleh.com/${i}`)) ) }; Now I have an array of Rx.JS observable I've created from promises that represent my queue. Now for the behavior of what I want, I want to issue Three-concurrent requests to the server Upon completion of a request, I would like a new request to fire. I can create a