C++11的并發框架:Async++
Async++是一個輕量級的C++11并發框架。其思想源于Microsoft PPL library 和 N3428 C++標準提案。
// Create a task which runs asynchronously
auto my_task = async::spawn([] {
return 42;
});
// Do other stuff while the task is not finished
while (!my_task.ready()) {
// Do stuff...
}
// Wait for the task to complete without getting the result
my_task.wait();
// Wait for the task to complete and get the result
int answer = my_task.get();
// Create a task with a preset value
auto my_task2 = async::make_task(42);
// Print the value stored in the task
std::cout << my_task2.get() << std::endl;
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!