2

perlthrtut の抜粋:

共有変数は、2 つ以上のスレッドが同時にそれを変更しようとしても、変数の内部状態が破損しないことを保証することに注意してください。ただし、次のセクションで説明するように、これを超える保証はありません。

マルチプロセッサ カーネル スレッドをサポートする Linux での作業。

すべてのスレッドが更新された共有変数の値を見るという保証はありますか? 上記のように perlthrtut のドキュメントを調べても、そのような保証はありません。

ここでの質問: それを保証するためにプログラムで何ができるでしょうか?

4

3 に答える 3

0

You seem to be confused as to what :shared does. It makes it so a variable is shared by all threads.

A variable is indeed guaranteed to have the value it has, no matter which thread accesses it. It's a tautology, so nothing can be done to programmatically guarantee that.

于 2015-01-02T03:17:02.267 に答える