1

MauriceBachのTheDesignof the Unix Operating Systemには、作成中にコンテキストスイッチが原因で二重リンクリストが破棄される可能性があることを示す例があります。(彼は、このような重要なコード領域でプロセッサレベルを上げることでこれを防ぐことができると言い続けていますが、そもそも問題を示しようとする彼の推論を理解するのに苦労しています)彼に含まれるサンプルコードは次のとおりです。次のとおりです。

struct queue {

} *bp, *bp1;
bp1 -> forp = bp -> forp;
bp1 -> backp = bp;
bp -> forp = bp1;
/* consider possible context switch here */
bp1 -> forp -> backp = bp1;

彼が書いた図は最初に示しています:

              |     |
              | bp1 |

->    |    |    ->         |    |
<-    | bp |    <-         |    |

次に、最終状態を表示するには:

->  |    |  ->  |     |   -> |    |
<-  | bp |  <-  | bp1 |      |    |
       ^
        \                       /
         ----------------------- 

ロジックをウォークスルーしようとしていますが、コードが示されているように二重リンクリストが壊れてしまう理由がわかりません。誰かがこの問題を引き起こすためにコンテキストスイッチ中に何が起こっているのか説明できますか?

(psは二重リンクリストとしてタグ付けされますが、タグ作成権限はありません)

4

1 に答える 1

1

My mistake in not reading carefully enough - Maurice says in the page before the diagrams how the context switch would break the code IF another process "were to manipulate the pointers on the linked list before the original process ran again." I was confused because I was trying to get enough information from just the diagram and the code, neither of which mentioned the fact that the process being switched to would be handling the same data structure in memory (despite there having been a context switch.. still not a 100% clear/motivated example imho). Either way, apparently my own kernel had a bit of data corruption when i made the context switch from reading one page to the next..

于 2011-05-23T00:30:56.880 に答える