DS
// control
unique_lock lock(mtx);
terminate = true;
lock.unlock();
cv.notify_all();
// worker
for(;;) {
unique_lock lock(mtx);
if(terminate)
return;
cv.wait_for(lock, seconds(1));
if(terminate)
return;
lock.unlock();
do_work();
}
Size: a a a
DS
// control
unique_lock lock(mtx);
terminate = true;
lock.unlock();
cv.notify_all();
// worker
for(;;) {
unique_lock lock(mtx);
if(terminate)
return;
cv.wait_for(lock, seconds(1));
if(terminate)
return;
lock.unlock();
do_work();
}
ПК
ПК
ПК
A
// control
unique_lock lock(mtx);
terminate = true;
lock.unlock();
cv.notify_all();
// worker
for(;;) {
unique_lock lock(mtx);
if(terminate)
return;
cv.wait_for(lock, seconds(1));
if(terminate)
return;
lock.unlock();
do_work();
}
A
DS
DS
DS
DS
АР
DS
DS
L
MО
ПК
L