You can embed user-mode threads in a non-threaded environment by dividing the self-written exit function in your code.
Similarly, you can freely scatter calls to the heart rate check functions in your code. Change the flow, just regularly call the heartbeat function, which checks if you still need to send a pulse.
This is a tough decision, but given that you have tried the right solution and it doesnβt work, maybe this is what you should return to.
In fact, what you could do is put a macro at the beginning of each function call, which makes a quick time check and, if necessary, calls the heartbeat function.
(, Java? , , ).
user82238