この記事は続き記事です。目次→C++11のthreadで遊んでみる - minus9dの日記 - mutexを使って排他制御 スレッドを4つ作って、それぞれのスレッドでIDを表示するプログラムを書いてみる。 #include <iostream> #include <thread> #include <vector> void worker() { std::cout << "thread id: " << std::this_thread::get_id() << std::endl; } int main() { // スレッドを4つ作る std::vector<std::thread> ths(4); for (auto& th : ths) { th = std::thread(worker); } // すべてのスレッドが終わるのを待つ for (auto& th : ths)