What's a good strategy for processing a queue in parallel?
问题 I'm writing a program which needs to recursively search through a folder structure, and would like to do so in parallel with several threads. I've written the rather trivial synchronous method already - adding the root directory to the queue initially, then dequeuing a directory, queuing its subdirectories, etc., until the queue is empty. I'll use a ConcurrentQueue<T> for my queue, but have already realized that my loops will stop prematurely. The first thread will dequeue the root directory,