Hardware: Particle Photon
I am looking at the possibility of spawning off threads to carry out work, but also being able to terminate them early if I no longer need what they are doing. So I have written the following test program which spawns a thread to rapidly flash d7 LED, then disposes it and slowly flashes D7 and repeats. After ~60secs of running the rapid flashing stops indicating that no new threads are being created, then a few seconds later the RGB LED goes to breathing green (CLOUD NOT CONNECTED mode).
Perhaps some resource is not being cleaned up?
int LED = D7;
Thread hardwareThread;
int controlParams[1];
os_thread_return_t testMethod(void* params) {
int *args = (int*) params;
int interval = args[0];
for(;;) {
digitalWrite(LED, HIGH);
delay(interval);
digitalWrite(LED, LOW);
delay(interval);
}
}
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
controlParams[0] = 50;
hardwareThread = Thread("hardware", testMethod, &controlParams);
delay(1000);
hardwareThread.dispose();
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
}
thanks,
Chris