nptl SIGCONT and thread scheduling

2019-07-15 09:12发布

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.

2条回答
Anthone
2楼-- · 2019-07-15 09:16

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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-07-15 09:22

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.

查看更多
登录 后发表回答