ftrias / TeensyThreads

MIT License
178 stars 26 forks source link

Slow running after restart #31

Open jthuermann opened 2 years ago

jthuermann commented 2 years ago

Hey, got a problem using your library: After I suspended my running thread and restarted it the while-loop is much slower

Code void setup() { int id = threads.addThread(drive); while (true) { if (digitalRead(BUTTON_PIN) == HIGH) { Serial.println("Debug: Button pressed"); if (threads.getState(id) == Threads::RUNNING) { threads.suspend(id); } else { threads.restart(id); } while (digitalRead(BUTTON_PIN) == HIGH) ; } } }

void drive() { int a = 0; while (true) { a++; Serial.print(millis()); Serial.print(": "); Serial.println(a); }

jthuermann commented 2 years ago

After the first start of the thread the time between two outputs is about 10 milliseconds, after the first restart up to 600 milliseconds.

Board: Teensy Arduino 4.0