Home > Software design >  Can Boost::asio::post can interrupt the running thread?
Can Boost::asio::post can interrupt the running thread?

Time:04-06

I am new to Boost::asio and I am currently looking at io_context. I have a question regarding the function io_context::post Posting on thread can preempt what's running on that thread currently ? because in the documentation i have seen : Deprecated: Use post.) Request the io_context to invoke the given handler and return immediately. I'm expecting that post will be added to the event queue, and will only be considered to run again when control is passed back to the event loop

CodePudding user response:

No it cannot interrupt the running thread(s) associated with the io_context. post() enqueues the task to the io_context which will execute it eventually. The "return immediately" is meant in terms of the post() call itself, not the task. So the post() function returns immediately without blocking, but the task is scheduled for later execution.

  • Related