All pastes #799531 Raw Edit

Untitled

public cpp v1 · immutable
#799531 ·published 2007-11-27 18:31 UTC
rendered paste body
#include <boost/thread.hpp>#include <boost/thread/once.hpp>#include <iostream>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;}