ivanseidel / ivanseidel/ArduinoThread

Using memory address as ThreadID sometimes gives different threads the same address

Aperta
#42 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C++
Stelle
974
Fork
197
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

In my program, I've created 3 threads and then added them all to a controller thread. However, one thread was never executed (I had print-statements that should have run) and after some debugging I noticed that the size of the controller thread showed 2, when it should have been 3. I did not use thread names. I am only using lambda functions as callback functions for the threads.

Looking at the thread-controllers add function, I saw that a thread is not added when the controller already has a thread with the same ID. I printed the thread-ids of all my threads and it turned out that the 1st and the 3rd thread got the same ID, so the 3rd thread was never added. But this should not be possible as different threads should get different ids?

When I added Serial.println() before and Serial.println(controller.size()) after adding the 3rd thread to the controller, all 3 threads got different IDs. I can not explain this behaviour.

Thus, my conclusion is that using memory address as ThreadID feels unpredictable. Maybe thread id could be substituted by a random number instead? (I did this as a workaround).

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia con la funzione add di thread-controllers e la generazione di ThreadID che utilizza gli indirizzi di memoria. Riproduci il caso con tre thread basati su lambda, confrontando i loro ID e la dimensione del controller con e senza chiamate a Serial.println(). Il lavoro è completato quando vengono mantenuti thread distinti e il controller segnala tutti e tre in modo coerente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
arduino, cpp
Ambito
embedded-iot
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.