Multithreaded execution where order of finished Work Items is preserved

后端 未结 9 1189
无人共我
无人共我 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:07

    Preprocess: add an order value to each item, prepare an array if it is not allocated.

    Input: queue (concurrent sampling with order values 1,2,3,4 but doesnt matter which tread gets which sample)

    Output: array (writing to indexed elements, using a synch point to wait for all threads in the end, doesn't need collision checks since it writes different positions for every thread)

    Postprocess: convert array to a queue.

    Needs n element-array for n-threads. Or some multiple of n to do postprocessing only once.

提交回复
热议问题