cybo
March 15th, 2010, 03:25 PM
it seems like some people think that i ask for solutions for homeworks on these forums, so right from the beginning i'd like to say that i never ask for solutions on forums, i'm not interested in them. in fact i don't even want to see the solutions. where is the fun in solving the problem when you already have the solution?
the following question is not a homework question, however it did come out of several homeworks i already solved and i'm simply curious about it. i also would like to say that i'm relatively new to threads but interested in learning more about them.
say i created several threads (using pthreads library). these threads need to do something when a signal arrives. this signal is periodic. how would you go about threads waiting for a signal to arrive?
below is some pseudo code:
void* mythread(void* arg) {
printf("i'm in the thread\n");
// wait for a signal to arrive
// after the signal arrived print this
printf("the signal has just arrived\n"); // this most likely will have to be done in the signal handler
}
i know how to setup the signal handler (through sigaction) and how to generate a signal but i can't figure out how to make a thread wait for signal.
any help is appreciated.
the following question is not a homework question, however it did come out of several homeworks i already solved and i'm simply curious about it. i also would like to say that i'm relatively new to threads but interested in learning more about them.
say i created several threads (using pthreads library). these threads need to do something when a signal arrives. this signal is periodic. how would you go about threads waiting for a signal to arrive?
below is some pseudo code:
void* mythread(void* arg) {
printf("i'm in the thread\n");
// wait for a signal to arrive
// after the signal arrived print this
printf("the signal has just arrived\n"); // this most likely will have to be done in the signal handler
}
i know how to setup the signal handler (through sigaction) and how to generate a signal but i can't figure out how to make a thread wait for signal.
any help is appreciated.