rendered paste body#include <boost/thread.hpp>
#include <boost/thread/once.hpp> // dla algorytmu boost::call_once
#include <iostream>
using namespace std;
using namespace boost;
int i = 0;
once_flag flag = BOOST_ONCE_INIT; // inicjalizacja flagi
void init()
{
++i;
}
void once_thread()
{
call_once(init, flag);
}
int main()
{
// tworzymy i startujemy w�tki
thread thrd1(once_thread);
thread thrd2(once_thread);
thrd1.join();
thrd2.join();
// wynik pokazuje, �e wywo�anie odby�o si� tylko raz
cout << i << endl;
// main() czeka na zako�czenie
system("PAUSE");
return 0;
}