Hello!
Though I have several years of programming experience, I have little experience with C++. So, maybe this topic belongs in the beginner section. I'm familiar with writing async code within a single thread. But, lately, I want more speed.
Generally, my question is this: If I have a blocking web server, can I have a non-blocking periodic timer on the same thread?
The specifics:
- I'm using
https://github.com/uNetworking/uWebSockets for a web socket server. For this server "The event loop will block until no more async work is scheduled, like for Node.js." So, after I start the server, no more code will be executed on the server-running thread
- While the server is running, I also need a periodic timer to broadcast messages to the clients at some interval. I've found some ways to implement a periodic timer, but ultimately they all block execution on the thread. Even the
boost::asio
timer with
async_wait()
will block once the timer is running.
My conclusion is that I must run this periodic timer in a separate thread, perhaps using
std::thread
with
detach()
. Is this reasonable?
P.S.: The preview feature was displaying an empty post before submitting this post. However, now that I'm editing it, the preview feature is working.