「バリアー!」
「デュクシ!」
「ちょっ、お前、オレ、バリアー張ってんだから攻撃するなよなー」
「うるせー、オレのはバリアー貫通できる攻撃だっつーの」
「貫通できないバリアー!」
「貫通できないバリアーを貫通できる攻撃!」
「絶対貫通できないバリアー!」
「絶対貫通できる攻撃!」
「そんな攻撃ねーよ」
「そんなバリアーこそねーよ」
「お前、矛盾って言葉、知ってるか?」
「ああ、昔の中国人はオレの矛を持ってなかったんだな」
「ちげーし。オレのバリアーを持ってなかったんだぜ」
「真似すんなよ」
「マネスンナヨー」
「あ、きったね」
「ア、キッタネ」
「飽きたね・・・」
「そうだね・・・」
フェンスといい、メモリバリアーともいう。名前はかっこいいが、やっていることは、あるスレッドにおけるあるメモリ場所に対する変更操作を、他のスレッドから見えるようにしたり、あるいは逆に、他のスレッドでの変更操作を、このスレッドから見えるようにすることである。
これは、多くのコンパイラーで、独自にサポートされている。基本的にWindowsでプログラミングを学んできた私としては、メモリバリアーという名称の方がしっくりくるのだが、C++の規格としては、フェンスという名称になっている。
C++0xの規格を眺めていたところ、どうもC++0x規格には、非アトミック操作に対するフェンスというものが、存在しないようである。
しかし、mutexはどうなるのだろう。例えば、以下のコードが、意図通りに動くことが、規格でどのように保証されているのだろうか。
std::mutex m ; int x ; void thread() { std::lock_guard<std::mutex> guard(m) ; ++x ; // 非アトミック操作 } int main() { x = 0 ; // 初期値0 std::thread A( thread ) ; std::thread B( thread ) ; A.join() ; B.join() ; std::cout << x << std::endl ; // 2であるべき }
色々と考えたあげく、以下のように考えた。
AとBのインクリメントは、1.10 [intro.multithread] p4に書かれているように、conflictする。
AとBで行われる非アトミック操作であるインクリメントは、mutexで囲まれており、同時には起こらないし、どちらかが先に起こることは確実である。とすれば、1.10 [intro.multithread] p13に書かれている通り、先に起こった方の操作は、後続の操作に対して、visible side effectである。
AとBのインクリメントはconflictするものの、どちらかが先に起こることが保証できるため、1.10 [intro.multithread] p21のdata raceの条件には引っかからない。
LISTER: Hey, it hasn't happened, has it? It has "will have going to have happened" happened, but it hasn't actually "happened" happened yet, actually.
RIMMER: Poppycock! It will be happened; it shall be going to be happening; it will be was an event that could will have been taken place in the future. Simple as that. Your bucket's been kicked, baby.
8 comments:
Thank you for sharing this useful article. Keep it up! Regards!
온라인카지노
All your hard work is much appreciated your thoughts. This content data gives truly quality and unique information. I’m definitely going to look into it. 카지노사이트Really very beneficial tips are provided here and, Thank you so much. Keep up the good works.
Your article is very interesting. I think this article has a lot of information needed, looking forward to your new posts.스포츠토토
Thank you for providing a good quality article.
온라인카지노
You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this. 메이저놀이터
An intriguing discussion may be worth comment. I’m sure you should write much more about this topic, may well be described as a taboo subject but generally folks are too little to chat on such topics. An additional. Cheers 토토사이트
I had a lot of fun at this Olympics, but something was missing. I hope there's an audience next time.안전토토사이트
Great writing to see, glad that google brought me here, Keep Up cool job.그래프사이트
Post a Comment