如果我使用 std::launch::async 策略启动 std::async ,它不应该在新线程中启动每个异步任务吗?目前看起来新的异步任务移动到刚刚完成它的工作的线程。我使用 VC11 作为我的编译器。正如您从输出中看到的,当使用 std::async 启动一个新的工作线程(例如,一个工作线程多次获取 ID 为 34500 的线程)时,它从一个先前完成的线程开始。我对 std::async 的理解是错误的,还是有潜在的工作窃取队列或类似的东西?
Worker (ID=24072) starting.
Worker (ID=34500) starting.
Worker (ID=32292) starting.
Worker (ID=31392) starting.
Worker (ID=17976) starting.
Worker (ID=31580) starting.
Worker (ID=33512) starting.
Worker (ID=33804) starting.
Worker 32292 finished.
Worker (ID=32292) starting.
Worker 17976 finished.
Worker (ID=17976) starting.
Worker 31580 finished.
Worker (ID=31580) starting.
Worker 34500 finished.
Worker (ID=34500) starting.
Worker 34500 finished.
Worker (ID=34500) starting.
Worker 32292 finished.
Worker (ID=32292) starting.
Worker 17976 finished.
Worker (ID=17976) starting.
Worker 34500 finished.
Worker 17976 finished.
Worker 31580 finished.
Worker 32292 finished.
Worker 33804 finished.
Worker 31392 finished.
Worker 33512 finished.
Worker 24072 finished.