I see. Well I've found some more basic examples to work with threads. What I first was trying to do was have multiple threads execute a looping count out of order. So here's what I got
I understand what is going on with my previous experience with java threads, the one thing I
using std::cout; using std::cin;
using std::endl; using std::string;
void count(int id)
for(int i = 0; i < 50; ++i)
cout << "THREAD " << id << ": " << i << endl;
for(int i = 0; i < 4; ++i)
1. When I "call tGroup.join_all() is it to ensure that main doesn't terminate before all the other threads do, or just ensure that all threads terminate naturally?
2. Why does the thread class throw a fit when I share a lock object with all threads. For example lk(ioMutex) would be declared globally, and each thread locks or unlock it as so.
Is this because during the execution, if lock is already locked, then a thread trying to obtain one gets an exception thrown at them, or becaus a lock object shouldn't be shared as such.