Synchronizing access to data
C / C++ / MFC
2
Posts
2
Posters
0
Views
1
Watching
-
What I am trying to do is each thread gets to print out its 5 characters before potentially yielding to another thread. It works but it does not do what I want. THanks for help.
for (unsigned i = 0; i < _repCount; ++i) {
unique_lock lck(mtx);
cv.wait(lck, []{return !inUse; });
inUse = true;
for (auto c : _printMe) {
cout << c;
cout.flush();
}
inUse = false ;
} -
What I am trying to do is each thread gets to print out its 5 characters before potentially yielding to another thread. It works but it does not do what I want. THanks for help.
for (unsigned i = 0; i < _repCount; ++i) {
unique_lock lck(mtx);
cv.wait(lck, []{return !inUse; });
inUse = true;
for (auto c : _printMe) {
cout << c;
cout.flush();
}
inUse = false ;
}