I have a couple of questions about threads on teensy 4.1
1: Can you call threads.suspend() from in side a thread? If I know the id of the thread can I suspend it from within that thread with the plan on restarting it from outside in the main loop. i.e.
threads.suspend(Lthread_id );
2. if a thread is suspended the while loop inside the thread is not executing, correct??
The situation I have is two threads running a PID on each for two separate motors, one motor per thread. The problem I am trying to solve is the annoying whine when the error is so small that the PWM period signal generated is not long enough to actually move the motors any longer but the error has not gone to 0. So I thought I could just suspend the thread when the error has reached an acceptable limit and then restart the thread when a new position is required.
What happened when I tried this was the while loop appears to still being executed as indicated by a simple serial.print of a "." at the top of the while and a print of "sus" at the error checking portion. to my surprise I got a continuous ".sus" which tells me the while loop is still executing. After adding a couple more prints to second thread using different char for second thread ("_" and "Lsus") I get a series of ".Rsus" followed by a series of "_Lsus" as if they are still running for their time slice.
I also noticed that the "SUSPENDED" state value is not recognized as defined by Arduino IDE
MazeToy:219: error: 'SUSPENDED' was not declared in this scope
219 | if ( threads.getState(Rthread_id) == SUSPENDED)
| ^~~~~~~~~
if I replace the SUSPENDED with the 4 value it works
obviously I am missing something
but cannot see it.
please be kind to the attached code, it is a work in progress.
1: Can you call threads.suspend() from in side a thread? If I know the id of the thread can I suspend it from within that thread with the plan on restarting it from outside in the main loop. i.e.
threads.suspend(Lthread_id );
2. if a thread is suspended the while loop inside the thread is not executing, correct??
The situation I have is two threads running a PID on each for two separate motors, one motor per thread. The problem I am trying to solve is the annoying whine when the error is so small that the PWM period signal generated is not long enough to actually move the motors any longer but the error has not gone to 0. So I thought I could just suspend the thread when the error has reached an acceptable limit and then restart the thread when a new position is required.
What happened when I tried this was the while loop appears to still being executed as indicated by a simple serial.print of a "." at the top of the while and a print of "sus" at the error checking portion. to my surprise I got a continuous ".sus" which tells me the while loop is still executing. After adding a couple more prints to second thread using different char for second thread ("_" and "Lsus") I get a series of ".Rsus" followed by a series of "_Lsus" as if they are still running for their time slice.
I also noticed that the "SUSPENDED" state value is not recognized as defined by Arduino IDE
MazeToy:219: error: 'SUSPENDED' was not declared in this scope
219 | if ( threads.getState(Rthread_id) == SUSPENDED)
| ^~~~~~~~~
if I replace the SUSPENDED with the 4 value it works
obviously I am missing something
please be kind to the attached code, it is a work in progress.