ivanseidel / ivanseidel/ArduinoThread
Using memory address as ThreadID sometimes gives different threads the same address
- 主要语言
- C++
- 星标
- 974
- 派生
- 197
- PR 合并指标
- 30 天内没有已合并 PR
描述
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).
贡献指南
这个仓库没有索引到贡献指南
调研方向
从 thread-controllers 的 add 函数以及使用内存地址生成 ThreadID 的部分开始。使用三个基于 lambda 的线程重现该情况,比较调用和不调用 Serial.println() 时它们的 ID 以及 controller 的大小。当不同的线程都被保留,并且 controller 始终报告全部三个线程时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- arduino, cpp
- 领域
- embedded-iot
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100