#include #include #include using namespace std; using namespace boost; int i = 0; once_flag flag = BOOST_ONCE_INIT; void init() { ++i; } void once_thread() { call_once(init, flag); } int main() { // tworzymy i startujemy watki thread thrd1(once_thread); thread thrd2(once_thread); thrd1.join(); thrd2.join(); // wynik pokazuje, ze wywołanie odbyło sie tylko raz cout << i << endl; // main() czeka na zakonczenie system("PAUSE"); return 0; }