Adding a timeout to an UDP socket server
I would instead use a single thread for both tasks and employ an epoll selector on the sockets with a certain timeout. To the best of my knowledge, this is more or less what popular networking frameworks (e.g., NodeJS, Nginx, Lighttpd, etc.) do. I always found waiting on a socket for an undetermined amount of time in a separate thread a waste of resources. That being said, YMMV.