-
Notifications
You must be signed in to change notification settings - Fork 199
Closed
Description
I want to create a thread dynamically, but if the time elapsed from the start is bigger than just-created thread interval the thread is invoked immediately.
@ivanseidel
Here is an example:
#include <Thread.h>
#include <ThreadController.h>
ThreadController controll = ThreadController();
Thread *selfCancellingThread = NULL;
Thread addingThread = Thread();
void selfCancellingCallback(){
controll.remove(selfCancellingThread);
delete selfCancellingThread;
Serial.println("Thread was self-destroyed");
}
void addingCallback(){
controll.remove(selfCancellingThread);
delete selfCancellingThread;
selfCancellingThread = new Thread(selfCancellingCallback, 2000);
controll.add(selfCancellingThread);
Serial.println("Thread was added");
}
void setup() {
Serial.begin(115200);
Serial.println("Start");
addingThread.setInterval(5000);
addingThread.onRun(addingCallback);
controll.add(&addingThread);
}
void loop() {
controll.run();
}
If I increase selfCancellingThread interval to 6000, then it will be called after (6000-5000) = 1 sec at the first invocation:
...
selfCancellingThread = new Thread(selfCancellingCallback, 6000);
...
Metadata
Metadata
Assignees
Labels
No labels

