Apr-28-2020, 02:24 AM
I think you are trying to solve the wrong problem. You shouldn't be looking for a way to stop a thread that may be sleeping, you should look for a way to write your program so it doesn't sleep. This is not only true of machine control and process control programs, but any kind of program that has to react to unpredictable inputs or events (like a user interface for example).
Machine control code should not have any waits. Machine control code should periodically read sensors and make decisions based on the sensor feedback. Maybe you will do this using events (call some function when a button is pressed), or maybe you will have a monitor with a callback (read sensor, if value above some level execute code). If you need to do something for a period of time you record a start time and periodically check if the wait period has expired. Maybe you will have a state machine. The longest your code ever waits for anything should be shorter than the fastest your code has to respond to something.
Machine control code should not have any waits. Machine control code should periodically read sensors and make decisions based on the sensor feedback. Maybe you will do this using events (call some function when a button is pressed), or maybe you will have a monitor with a callback (read sensor, if value above some level execute code). If you need to do something for a period of time you record a start time and periodically check if the wait period has expired. Maybe you will have a state machine. The longest your code ever waits for anything should be shorter than the fastest your code has to respond to something.