Multithreaded execution where order of finished Work Items is preserved

后端 未结 9 1492
无人共我
无人共我 2021-02-01 08:28

I have a flow of units of work, lets call them \"Work Items\" that are processed sequentially (for now). I\'d like to speed up processing by doing the work multithreaded.

<
9条回答
  •  忘掉有多难
    2021-02-01 09:01

    You could have 3 input and 3 output queues - one of each type for each worker thread.

    Now when you want to insert something into the input queue you put it into only one of the 3 input queues. You change the input queues in a round robin fashion. The same applies to the output, when you want to take something from the output you choose the first of the output queues and once you get your element you switch to the next queue.

    All the queues need to be blocking.

提交回复
热议问题