#Recv loop in a pthread - how to exit

6 messages · Page 1 of 1 (latest)

teal kindle
#

A friend is doing a basic program where you have a pthread that does

while (recv(...)) {...}
```is there any mechanism for interrupting that recv from another thread (apparently you can signal threads and make recv return EINTR that way, maybe that's a solution - seems like a race though)
My initial idea is to `poll` on that socket and a `pipe`, and then write to the pipe from a separate thread to indicate an exit, but using a pipe as a condition variable seems wrong, but you can't poll a condition variable.
verbal shoalBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

scarlet minnow
#

Don't allow recv to block your execution and you can periodically check if you should break.

teal kindle
#

@scarlet minnow a timeout loop is indeed what we ended up doing, ty, though it feels wrong.

verbal shoalBOT
#

@teal kindle Has your question been resolved? If so, run !solved :)

teal kindle
#

!solved