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.

YouTube - Red Dwarf I - Future Echoes - Part 3 of 3


casinosite777.info said...

Thank you for sharing this useful article. Keep it up! Regards!

baccaratsite.top said...

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.

sportstoto.zone said...

Your article is very interesting. I think this article has a lot of information needed, looking forward to your new posts.스포츠토토

baccaratsite.biz said...

Thank you for providing a good quality article.

메이저놀이터 said...

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. 메이저놀이터

Unknown said...

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 토토사이트

안전토토사이트 said...

I had a lot of fun at this Olympics, but something was missing. I hope there's an audience next time.안전토토사이트

Unknown said...

Great writing to see, glad that google brought me here, Keep Up cool job.​​그래프사이트