Boost logo

Boost Users :

Subject: [Boost-users] What is the effective way to use boost::asio::deadline_timer for udp socket receive_from?
From: jupiter (jupiter.hce_at_[hidden])
Date: 2017-04-12 11:17:41


My program needs a sync udp socket send / receiver so I use the
deadline_timer as timeout for udp socket receive_from on Debian Jessie:

boost::asio::deadline_timer deadline(io_service,

In checkDeadline function, when the timer expires, it calls socket.cancel,
otherwise calls the deadline.async_wait(checkDeadline); again.

Apparently when the program runs to socket.receive_from(), it is blocked
and the timer is never called because both socket.receive_from and the
timer in the same thread.

I've been thinking to run the timer in another thread, but I checked
Internet, there are comments said deadline_timer is not thread safe, please
correct me if I am wrong here. It will be a simple solution for me if I can
run timer on another thread. Anyone has other ideas to run the timer

Appreciate your comments.

Thank you.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at