views:

37

answers:

2

Hello, I'm trying to port a code that relies on SIGCONT to stop certain threads of an application. With current linux nptl implementation seems one can't rely on that in 2.6.x kernels. I'm trying to devise a method to stop other threads. Currently I can only think on mutexes and condition variables. Any hints is appreciated.

A: 

How are you sending the signals to the target thread? If you use pthread_kill() to send SIGSTOP / SIGCONT to a single thread, it should work.

caf
With current kernels, ie nptl implementation SIGSTOP stops the whole process not just a single thread even with pthread_kill or setting the appropiate signal mask per thread.
piotr
+1  A: 

If you are relying on stopping and resuming other threads, then your application will eventually fail.

That is because, you cannot guarantee that you're not going to stop a thread while it has a mutex taken which protects a shared resource. This would result in deadlock, as any other threads (possibly including the one which stopped the first thread) which then need to wait for the mutex, will wait forever.

I'm sure it is possible, but also, you're doing it wrong.


NB: such mutexes probably exist in parts of the C library, even if you have none in your own code. If you have none in your own code and it is nontrivial, I'd be surprised.

MarkR
As I said, I'm trying to port code. It's not my design. Thanks for the comments about the hidden mutexes though.
piotr
I've hit mutexes in the C library before - in the related case of forking a multi-threaded program.
Douglas Leeder
I've hit those too, in the part that syncs C stdio with C++ stdio.
piotr