implementing future::then() equivalent for asynchronous execution in c++11

前端 未结 3 1529
既然无缘
既然无缘 2020-12-04 17:55

I have a few questions about the implementation of the function then() in Herb Sutter\'s talk. This function is used to chain asynchronous operations, the param

3条回答
  •  臣服心动
    2020-12-04 18:36

    The problem with this approach to .then() is that you spawn 2 threads (that is costly) simultaneously, and second of them would block on its future.get/wait (if the first one would run long enough, of course) So, its better to use the work queue, to serialize the jobs execution order (and re-cycle the existing threads). Just look for a good Thread pool pattern implementation

提交回复
热议问题