How can I pause a thread?

Hi all,

I start a pthread then I have a main loop inside my main process. From the main loop, I would like to pause the execution of the thread then resume it later. I’ve try using pthread_kill(thread,SIGSTOP) then later pthread_kill(thread, SIGCONT) but not only the thread stop. The hole process does and that’s not what I’m looking for. I only want to pause a given thread. Is it possible? How can I do that without adding pthread code inside the thread function? I’ve read that SIGSTOP cannot be masked like SIGKILL.

Any suggestion are welcome,



The idea of “Pause another thread whereever it is” is usually not good. Can you explain why you want to do that?

Under QNX6 SIGKILL cannot be mask.

I’m translating a robot controler from IRMX to QNX. In the controler, the main process was fork to keep the higher level control of joint/motor while a child process was controling the trajectory. I would like to keep it that way but since I have thread already runing or that has run, the fork function always return the not implemented like says in QNX documentation. Fork cannot be call once you have create a pthread. From the robot pendent, I can pause or resume the child process without loosing the control of my motor. At that point, I want to avoid to redesign the controler since I have to keed the same behavior for both QNX and IRMX controler. Since I cannot use fork, my only option is to use pthread but I have to be able to pause and resume and I don’t want to add lines to sync the child/thread with the main process like using semaphore or other conditional variables. That is why I was looking for a way to pause and resume a thread that is not so important to stop/resume anywhere.

I have found on the internet that HP has pthread_suspend() and pthread_continue() for that (both are supposed to be posix!). I imagine that QNX hasn’t implemented them yet!

Hope that explain my question a bit more!

Best regards all,


Like other UNIX flavor. I wasn’t thinking about masking SIGKILL. I was just saying thar SIGSTOP cannot be mask. I would have try to mask SIGSTOP for the main process and thread that are not supposed to get it and sent the SIGSTOP signal. But no can do since SIGSTOP isn’t maskable.



There is a ThreadCtrl() which will halt all threads but the calling one in a process. It’s evil and has many bad side effects, like not ensuring that mutexes are unlocked, etc. So it’s pretty easy to reach deadlock situations.

Why not just use priorities? These will effectivly stop any other threads in the entire system running if the priority is high enough.

The other alternative I think you could is, is instead of fork() the child process, your can “spawn()” it. Just pass enough information for the chile to run on the command line.

This way, you keep your child as a seperated process. Of cause, this method depends on how many data your child process going to inherit from main process.

Btw, I checked my posix book, pthread_continue/suspend is not Posix.

int main (int argc, char **argv) 
    if (strcmp(argv[0], "robot_child") == 0) {
            return child_start(argc, argv);

      /* main process */

      child_pid = spawnl(P_NOWAIT, /fullpath/robot, "robot_child",  child_param1, ... NULL);

ThreadCtrl! I forgot to mention that I use Neutrino and ThreadCtrl is not available in the doc or the include!

I’ve try to change the priority but since my controler is almost my only application, the CPU has enough idle time to run my thread at lowest priority available!!!

Thanks for the feedback,

Spawn is not realy what I was looking for since a would rather not have two binaries! I was planing to use fork without the exec part. It works well if no thread were created but since I have thread runing fork is not implemented for that!

By the way, I’ve seen that a open source teem were developping a succesor to PThread NPTL. On of the thing they want to have control of is the pthread_suspend and pthread_continue. Might be available in the future!!! :smiley:

Thanks for the info,


It’s actually ThreadCtl, and there are docs for it in the Neutrino Library Reference.

You missed it, it HAS to be there. Unless you are talking Neutrino 1.0 maybe?

Lower the thread to priority 2 (example) and start a thread at priority 3 that busy loops, that will stop the thread running at priority 2.

I’ve mispell it!!! My mistake! :blush:

Thanks, I’ll take a look!


I’ve try it without complete succes, but I’ll try it again to make sure!



It’s ThreadCtl not ThreadCtrl ;-)

I found out why it didn’t work out at first time. My thread at priority 3 wasn’t busy enough since I’d put a printf in it (which is a system call at the same time)!!! I only put a counter this time and it works fine!!! Case solves! 8)

Many thanks,