c++17

C++ async programming, how to not wait for future?

≡放荡痞女 提交于 2020-08-26 13:46:48
问题 I'm trying to learn async programming in C++. In Python, we have await , with which we can resume a function from that point, but in C++ future waits for the results and halts the next line of code. What if we don't want to get the result, but instead continue to the next line of code? How can I do this? 回答1: You can use std::future::wait_for to check if the task has completed execution, e.g. : if (future.wait_for(100ms) == std::future_status::ready) { // Result is ready. } else { // Do

C++ async programming, how to not wait for future?

有些话、适合烂在心里 提交于 2020-08-26 13:45:50
问题 I'm trying to learn async programming in C++. In Python, we have await , with which we can resume a function from that point, but in C++ future waits for the results and halts the next line of code. What if we don't want to get the result, but instead continue to the next line of code? How can I do this? 回答1: You can use std::future::wait_for to check if the task has completed execution, e.g. : if (future.wait_for(100ms) == std::future_status::ready) { // Result is ready. } else { // Do