Re: Closing an accepting BSD socket from a different thread

Marc Herbert

On 23 May 2019, at 23:29, Stephan Gatzka <> wrote

variables. E.g., following is a well-know pattern:
=== main loop thread ===
while (!should_exit) {
poll(..., MAIN_LOOP_PERIOD);
=== other threads ===
should_exit = true;
Yeah sure, put this is polling and a waste of resources.
Even if MAIN_LOOP_PERIOD is somewhat longer than the network protocol timeout(s) after which the socket should be closed anyway if the other end disappears?
Well, for a normal socket connection this might be probably o.k., but what about a server socket blocking on an accept() There is no such thing like a network timeout.
You could have a second poll() thread for all accepts with a much bigger ACCEPTS_LOOP_PERIOD; hours or even days.

Join to automatically receive all group messages.