-
Notifications
You must be signed in to change notification settings - Fork 10
Chapter 02, Managing threads
kPhantasm edited this page Dec 5, 2015
·
5 revisions
- C++프로그램은 런타임에 시작되는 main()스레드를 가지고 있으며, 다른 함수를 가진 추가 스레드를 실행시킬 수 있다.
- main()함수가 반환될 때, 프로그램이 종료되듯이 스레드도 종료된다.
- 스레드는 스레드에서 수행할 작업을 지정하는 std::thread 객체를 구축함으로써 시작된다.
void do_some_work();
std::thread my_thread(do_some_work);
class background_task
{
public:
void operator()() const
{
do_something();
do_something_else();
}
};
background_task f;
std::thread my_thread(f);