Problem with infinite loop in signal handler

This is a discussion on Problem with infinite loop in signal handler within the C Programming forums, part of the General Programming Boards category; Hi all,
I have problem with handling signals in simple program. Program starts
one thread (only task of this thread ...

Problem with infinite loop in signal handler

Hi all,
I have problem with handling signals in simple program. Program starts
one thread (only task of this thread is printing "Hello World") and
after while sends signal to this thread (signal handler is previously
registered). In signal handler is infinite loop that should suspend
thread forever. But it suspends whole application. I think this
problem is related with printf function because when I replace it with
with linux write sys function problem does not occures. And one more
info: problem occures not always, but most of time; maybe somewhere
there is a race condition.
This is whole code of application:

The absolute WORST way to do this. You max out the processor for nothing. Very bad thing to do. Use sleep() or if 1 second is too long, nanosleep().

The reason the signal handler suspends the whole program is because the signal handler applies to the whole program, not just the thread. If you move the signal handler to the thread, it will work the way you want:

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

His code doesn't which is a problem. That doesn't change that fact that thread procedure functions are defined as void* (*proc)(void*)

Yeah. I've barely written anything with threads but I just noticed I did use void*, so hopefully there was a good reason, since I didn't return anything either -- the threads have the same lifespan as the program. Will edit my post.