Way to Promise the io_service.run() Is Running
Hi ! I have a program which has a following logic 1. Start the UDP listening in daemon thread 2. Send the UDP command from main thread, and wait the response, maybe from the local So the program itself might also receive the message from second step. But the problem is, on Windows, the receiving thread will be executed before the main thread starts to send message, so the behaviour is correct. On Linux that's opposite, the main thread will be in deadlock because the 1st thread is not running and 2nd step it's trying to receive something after sending the command. My question, in the main thread of my application, what could I do to detect the io_service is running ? I tried to call m_io_services.stopped() seems the state is not correct, so I'd like to know how can I wait until the event loop in 1st step is running ? Thank you very much !
On 3/16/2016 9:58 AM, Bo Zhou wrote:
Hi !
I have a program which has a following logic
1. Start the UDP listening in daemon thread 2. Send the UDP command from main thread, and wait the response, maybe from the local
So the program itself might also receive the message from second step.
But the problem is, on Windows, the receiving thread will be executed before the main thread starts to send message, so the behaviour is correct.
Use a synchronization primitive so that the daemon thread does not do any UDP listening until the main thread has sent the UDP command.
On Linux that's opposite, the main thread will be in deadlock because the 1st thread is not running and 2nd step it's trying to receive something after sending the command.
My question, in the main thread of my application, what could I do to detect the io_service is running ? I tried to call m_io_services.stopped() seems the state is not correct, so I'd like to know how can I wait until the event loop in 1st step is running ?
Thank you very much !
participants (2)
-
Bo Zhou
-
Edward Diener