Search code examples
.netpipeline

How can pipeline tasks run concurrently if each task depends on the previous output?


On MSDN it says that each task is processed concurrently and each subsequent task depends on the output from the previous. However how can they occur concurrently if the processing of the subsequent task needs the output from the previous in order to even process something? Doesn't this imply that a task needs for the task that precedes it to complete it's execution before it can begin? (which doesn't sound very concurrent or parallel to me)

For example in their diagram they show the processing of a string with these steps

  1. Read string
  2. Correct case
  3. create sentences
  4. write output

How can i work on creating sentences before I read all the strings with corrected case?

The assembly line analogy also doesn't sound very parallel to me since if one stage in the assembly breaks then how can the partially constructed product move to the next state for further assembly.


Solution

  • Individual items are processed sequentially, but the processing of the entire sequence of items happens in parallel (mostly). As soon as an item is finished being processed by a given task, it is sent to the next task, which starts processing it right away. Without pipelines, the first task would have to process the entire sequence of values before the second task could start. This image from the MSDN article should help:

    enter image description here