ivanseidel / ivanseidel/ArduinoThread

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

オープン
#42 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
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 ベースのスレッドを 3 つ使ってケースを再現し、Serial.println() の呼び出しがある場合とない場合で、それらの ID と controller のサイズを比較します。3 つの異なるスレッドが保持され、controller が一貫して 3 つすべてを報告すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
arduino, cpp
領域
embedded-iot
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。