Gulzt (3) [Avatar] Offline
#1
Both listings define the following function.
void push(T new_value)
{
    std::lock_guard<std::mutex> lk(mut);
    data_queue.push(new_value);
    data_cond.notify_one();
}


According to your text it 4.1.1, the lock_guard should be in its own scope:
void push(T new_value)
{
    {
        std::lock_guard<std::mutex> lk(mut);
        data_queue.push(new_value);
    }    
    data_cond.notify_one();
}

Note that we put the code to push the data onto the queue in a smaller scope, so we notify the condition variable after unlocking the mutex — this is so that if the waiting thread wakes immediately, it doesn't then have to block again, waiting for us to unlock the mutex.

Another small one, you forgot a semicolon in listing 4.7, line 24.