Hi Werner,
OK now that I have PellesC version 10 running I can help in your quest. I hope
So first there is the matter of interpreting the instructions.
The C standard states in 7.26.5.7 p. 2:
"The thrd_sleep function suspends execution of the calling thread until a signal which is not being ignored is received."
This is true, but what it does not do is
terminate the thrd_sleep() function or the _sleep() function. Using a signal the thrd_sleep can be paused, other work done, but then it is resumed.
I'm fairly sure this is/was not your expectation.
To actually terminate the different sleeps you can break up the sleep into loops of the smallest interval you are willing to have. Note that no sleep guarantees the exact sleep interval even without looping.
I've modified your code to show this. The modified code lets you choose to use thrd_sleep, or _sleep(), choose to use a loop method or just straight sleep method. The screen output is much more detailed to show timing results. If you run it as posted (loop method) you will see an escape from the thrd_sleep set for 15 sec, with main sleep at 5 before signaling, results in showing 10 sec remaining. Then change to not using a loop to see the output.
In the signal handler I just set a kill flag but other procedures could be called too. PellesC doesn't currently support thrd_kill() which could simplify it too.
To change operation change the defines at the start of the program and recompile.
Here it the output:
----Entered destructor with 1----
Time 07:51:18 - Initiate sig handler for New_Thread, ticks 34143895461518
Time 07:51:18 - In Main back from thrd create 5 sec, total ticks were 0
Time 07:51:18 - Signal handler for New_Thread install succeeded, ticks 34143895461518
Time 07:51:18 - Main thrd_sleep Start ticks 34143904744397
Time 07:51:18 - New_Thread thrd_sleep Start at 34143905066208 for 15
Time 07:51:23 - Main thrd_sleep End
5 sec, total ticks were 11532863889
Time 07:51:23 - Main thrd_sleep residual
0 sec
Time 07:51:23 - Going to raise signal to stop thread, ticks 34143904744397
Time 07:51:23 - Interrupt signal received 34155444130170 ticks.
raised SIGINT
Time 07:51:23 - sig_handler alerted at 34155446511792 ticks.
Time 07:51:23 - Signal handler finished its job, ticks 34143904744397
Time 07:51:23 - New_Thread
15 sec thrd_sleep total ticks were 11604411594
Time 07:51:23 - New_Thread terminate with
10 sec remaining 10
Start 3078, End 3083. Remaining 10
Time 07:51:23 - New_Thread terminating, ticks 34143905066208
Time 07:51:23 - New thread successfully joined, ticks 34143904744397
Sleeping time of "thrd_sleep" in "New_Thread":
Interuption:
Remaining secs = 10
Remaining nsecs = 0
Press any key to continue...
---------------------------------
Hope this helps,
John Z