// Remember to compile with -pthread

#include <iostream>
#include <thread>
#include <vector>

using std::cout;
using std::cerr;
using std::endl;
using std::vector;
using std::thread;

const int NUM_THREADS = 4;
const int LOOP_NUM = 500;

void thread_main(int num) {
  for (int i = 0; i < LOOP_NUM; i++) {
    cout << "[thread: " << num << "] " << i << endl;
  }
}

int main(int argc, char** argv) {
  vector<thread> thds;

  for (int i = 0; i < NUM_THREADS; i++) {
    thds.emplace_back(thread_main, i);
  }

  for (int i = 0; i < NUM_THREADS; i++) {
    thds[i].join();
  }

  return 0;
}