multithreading - Safely close an indefinitely running thread -


so first off, realize if code in loop use do while loop check variable set when want thread close, in case not possible (so seems):

dword winapi recv thread (lpvoid random) {     recv(clientsocket, recvbuffer, recvbuflen, 0);     return 1; } 

in above, recv() blocking function. (please pardon me if formatting isn't correct. it's best can on phone.)

how go terminating thread since never closes never loops?

thanks, ~p

amongst other solutions can

a) set timeout socket , handle timeouts correctly checking return values and/or errors in appropriate loop:

setsockopt(clientsocket,sol_socket,so_rcvtimeo,(char *)&timeout,sizeof(timeout)) 

b) close socket recv(..) returning blocked state error.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -