samedi 28 mars 2015

Will signals be delivered to a program blocked on POSIX semaphore?



This really is two questions, but I suppose it's better they be combined.


We're working on a client that uses asynchronous TCP connection. The idea is that the program will block until certain message is received from the server, which will invoke a SIGPOLL handler. We are using a busy waiting loop, basically:



var = 1
while (var) usleep(100);

//...and somewhere else
void sigpoll_handler(int signum){
......
var = 0;
......
}


We would like to use something more reliable instead, like a semaphore. The thing is, when a thread is blocked on a semaphore, will the signal get through still?


Side question (just out of curiosity):


Without the "usleep(100)" the program never progresses past the while loop, although I can verify the variable was set in the handler. Why is that? Anything that triggers a context switch seems to work, e.g. printing to the console.


Cheers!




Aucun commentaire:

Enregistrer un commentaire