2つのスレッドが同時にフラッシュに書き込むことができるので、セマフォを使用します。しかし、以下のバージョン1のlogmytext()関数は、 "内部"セマフォを非リエントラントにすることはできますか?私。 2つのテキストが混乱する可能性はありますか?埋め込み型Cでのセマフォおよび非リエントラント関数
version2には、「外部」セマフォ(主に多くの入力が必要)が必要です。それともあまりにも心配しているだけですか? (注:これは擬似コード-Cであり、 "外部"と "内部"は文字通り取られません)。
バージョン1:
thread_a() {
logmytext("Just started A");
}
thread_b() {
logmytext("Just started B");
}
void logmytext(atextstring) {
grabsemaphore(); // has tread_b text overwritten thread_a text now?
writetoflash(atextstring,1,2,3);
releasesemaphore();
}
バージョン2:logmytext
への呼び出しが保護されているので、
thread_a() {
grabsemaphore(); // stop before the potential danger.
logmytext("Just started A");
releasesemaphore(); // but a lot of code to type.
}
thread_b() {
grabsemaphore();
logmytext("Just started B");
releasesemaphore();
}
void logmytext(atextstring) { // no semaphore in here
writetoflash(atextstring,1,2,3);
}
grab-とreleasesemaphoreが同じセマフォを使用する場合は、バージョン1が問題ありません。 – alain
それぞれ同じ*セマフォーについて話している限り、2つのバージョンは同じでなければなりません。 –