1

I have the following problem: I have large chunks of data and I want different threads to process a part of this data in parallel. First synchronization must take place here, such that all threads wait until the last thread has finished its process. Then, I want to trigger a writer-reader mechanism: Thread 0 makes a calculation using the data it has gathered from the data chunk and after it has done with the calculation, thread 1 starts to process its output. Thread 2 then uses thread 1's output and so on, in this particular order. After all threads finished this writer-reader sequence, they begin to work on the next data chunk.

I may implement this using fancy locking mechanisms but I am very positive that there should be special Task Parallel Library methods which I can use for a more easy and efficient solution. Are there any such methods in TPL that I can use for this kind of problem?

Ufuk Can Bicici
  • 3,589
  • 4
  • 28
  • 57
  • Take a look at [`TPL Dataflow`](https://msdn.microsoft.com/en-us/library/hh228603%28v=vs.110%29.aspx) – Yuval Itzchakov Feb 26 '15 at 12:49
  • 5
    If thread N-1 output is used as thread N input than it's essentially a sequential process, hence there's no point in using threads. In my opinion it would be more natural to have each thread doing all the work on one data chunk, than launch those threads in parallel. Or i might misuderstand your setup completely. – J0HN Feb 26 '15 at 12:50
  • 1
    thread.Wait() and Thread.WaitAll() are your friends, see the following : http://stackoverflow.com/questions/4190949/create-multiple-threads-and-wait-all-of-them-to-complete – Johan Feb 26 '15 at 12:51
  • 1
    What @J0HN said. However, this question does seem similar to [this one](http://stackoverflow.com/questions/28453347/how-to-make-threads-go-through-a-gate-in-order-using-c-sharp/28454179#28454179). – Matthew Watson Feb 26 '15 at 12:52
  • @MatthewWatson Your answer for the question in the link is what I am looking for. Thanks for help! – Ufuk Can Bicici Feb 26 '15 at 13:27

0 Answers0