How do I make a function asynchronous in C++?

后端 未结 7 573
别跟我提以往
别跟我提以往 2021-02-02 11:21

I want to call a function which will be asynchronous (I will give a callback when this task is done).

I want to do this in single thread.

7条回答
  •  名媛妹妹
    2021-02-02 12:05

    The long answer involves implementing your own task scheduler and wrapping your "function" up into one or more tasks. I'm not sure you want the long answer. It certainly doesn't allow you to call something, completely forget about it, and then be notified when that thing is done; however if you are feeling ambitious, it will allow you to simulate coroutines on some level without reaching outside of standard C++.

    The short answer is that this isn't possible. Use multiple threads or multiple processes. I can give you more specific information if you divulge what OS/platform you're developing for.

提交回复
热议问题