ftrias / TeensyThreads

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slow running after restart

jthuermann opened this issue · comments

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);
}

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