[Software]/Programming Tips2014. 5. 22. 08:43

ubuntu12.04 기준 c++11 concurrency library compile and test 방법


ubuntu12.04는 gcc/g++ 4.6이 설치되어 있으므로 gcc/g++ 4.7 (or 4.8) 을 설치한다.

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.7 g++-4.7

기존 gcc/g++을 대체하고 싶을 경우 사용
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20 sudo update-alternatives --config gcc sudo update-alternatives --config g++

아래 명령어로 compile 한다.

bart@BHNMCX1-LNX:~/temp$ /usr/bin/g++-4.8 main.cpp -o a -std=c++0x -lpthread

concurrency 관련된 sample code를 사용할 때는 반드시 -lpthread를 넣도록 한다.


std::async 함수를 사용할 때 compile time에 std::launch::async, std::launch::deferred 가 결정된다(?)
async thread로 실행하고 싶으면 반드시 아래와 같이 option을 주고 실행한다.

auto f1 = std::async(launch::async, functor1);

Posted by 바트정