I have written a multi-threaded resource manager to manage incoming packets from a microcontroller which works fine. Now however, I want to add some watchdog timers to ensure that everything keeps moving properly.
I have come up with two options and it would be a great help if somebody could recommend one or the other and explain why.
(i) I could set up a timer that sends pulses on expiry. As I already have a dispatch interface, I could use pulse_attach(…) to catch the pulses. A “watchdog” function would then increment a variable and send a “stay awake” message to the hardware if the variable was over a certain value(i.e it has timed out).
If the hardware is functioning normally it sends a pulse that will result in the same variable being decremented (preventing a timeout).
As I am using a thread pool, will a new thread be started every time a pulse is received by dispatch_block() or will the pulses be queued until the last call to the pulse_attach function has completed?
(ii) My other option was to start a totally independent (of the TPool) thread and have it block on a MsgReceivePulse(…) . I would start a timer and create a channel linking the thread and the timer. Every time the timer expires the thread increments or decrements the variable, as before. This way I could ensure that there was never any more than one thread running that dealt with the watchdog timers .
In general, how does a thread pool decide how to allocate another thread for a task? e.g. I have calls to the select_attach and pulse_attach functions. Will it create a new thread that handles all select calls and one that deals with pulses, or will it create a new thread for every call to either the select_attach or pulse_attach functions?
I hope my question is clear and thanks in advance for any help that you can give.