Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ multithreading synchronization

Here is a simplified version of my problem.

There are N threads executing following 3 instructions in an infinite loop:

A -> B -> C -> A -> B -> C -> A -> B -> .......

I want that all threads execute instruction B concurrently i.e. execution of B by any thread should start only if all threads have reached B. So, if there is a thread that has executed B -> C -> A, it should wait here till other threads are also ready to execute B.

If possible, please let me know a portable solution that'll work on both windows & MAC.

like image 506
arvin Avatar asked Nov 14 '11 13:11

arvin


1 Answers

You should check out the Boost thread library, especially the section about condition variables.

like image 86
Some programmer dude Avatar answered Sep 27 '22 16:09

Some programmer dude