c - Interrupt a accept() that is waiting, just changing a global variable value -
i'm doing project university, chat system server , multiple clients. in specification document there written: the main thread controlled loop on global var go, , @ each cycle waits connection request user and also: server stops sigterm or sigint. when signal received, global var go set zero, , threads exit loop cycle so, thread main create socket, bind port , @ every new connection accept() , create thread worker takes care of communication client. my problem exiting thread main changing global var. in thread main if do while (go && accept(params)) {} it doesn't enter in while loop. so @ moment code while (go) { accept(params); // stuff } and, well, when set go 0 waits on accept , have create new connection, accepts connection , exit thread 'cause go becomes zero. same problem thread worker while (go && read(socket_id, buffer, sizeof(char)) > 0) {} it waits char socket exit loop. i don't see way...