I have class A and classes B and C.
class B runs one thread and class C runs n threads.
class A should start the threads and than wait for a signal from the user (say Ctrl-c in Linux) – class A will stop all threads (of classes B and C), do some final work and the application will exit.
The question is: how should class A sleep until signal received? what is the best implementation?
Sounds like a job for a condition variable. There’s a tutorial on how to use pthreads condition variables here and another one on wikipedia here
The basic approcah is that all the threads that you want to kill periodically call pthread_cond_timedwait to check if a signal has been sent from class A.
In pseudocode each of your threads in classes B and C would look something like this
then in class A’s signal handler that catches the CTRL-C (or whatever signal)