What does sig in int pthread_kill(pthread_t thread, int sig) refer to? Are there predefined sigs? :S
+1
A:
A little Google goes a long way:
http://opengroup.org/onlinepubs/007908775/xsh/signal.h.html
There's a table about 1/4th of the way down the page you might find handy.
KevenK
2010-07-01 12:23:36
What if I want to use it to interrupt sleep()? SIGCONT doesn't seem to work.
lies
2010-07-01 12:38:21
SIGCONT is, AFAIK, only used for terminal processes and only used in conjuction with SIGSTOP. You send SIGSTOP to stop the process, SIGCONT to tell it to continue. sleep will only be interrupted if a signal that is not ignored arrives; I would suspect if the process is not stopped, SIGCONT will be ignored. You could try SIGUSR1. Remember you also have to set up a signal handler in the thread that is running to catch whatever signal you want to use; otherwise a signal will typically terminate the process.
Jack Lloyd
2010-07-01 12:53:04
What do you mean by "you also have to set up a signal handler in the thread that is running to catch whatever signal you want to use"? What does "a signal that is not ignored arrives mean"? How do I send a signal that is not ignored?
lies
2010-07-01 13:09:02
+2
A:
In reply to your comment about interrupting sleep: Instead of attempting to force signals to work here, have you considered instead of sleep
using pthread_cond_timedwait
instead? It lets you effectively sleep and provides a thread-safe mechanism to abort the sleep early via a pthread_cond_signal
.
Mark B
2010-07-01 13:40:42
I did consider it but I am trying to avoid using conditions, if that is possible.
lies
2010-07-01 13:45:50
@return: That seems some strange reasoning: avoiding condition variables, but then resorting to signals, especially since you don't seem to be comfortable with signal-handlers. Any reasons why?
stefaanv
2010-07-01 14:55:33