With UDP, you could send the socket a datagram from another thread, so unblocking the read(). The datagran could, (depending on your protocol), contain a 'suicide' command or you could use an additional 'shutdown' boolean that the thread reads after read() returns.