I was looking at this article about conditon_variables.
http://www.justsoftwaresolutions.co.uk/threading/condition-variable-spurious-wakes.html

For a timeout, the article has the following sample program with condition variables.

    template<typename Duration>
    bool timed_wait_and_pop(Data& popped_value,
                            Duration const& wait_duration)
    {
        boost::system_time const timeout=boost::get_system_time()+wait_duration;

        boost::mutex::scoped_lock lock(the_mutex);
        while(the_queue.empty())
        {
            if(!the_condition_variable.timed_wait(lock,timeout))
                return false;
        }
        
        popped_value=the_queue.front();
        the_queue.pop();
        return true;
    }

However, shouldn't this program instead start with

        boost::mutex::scoped_lock lock(the_mutex, timeout);
        if(!lock.owns())
              return false;


i.e. shouldn't it also take care of getting stuck while locking the mutex.

i.e. if the timeout is 5 seconds & the getting the lock itself takes 10 seconds,
then, the earlier the program will return is 10+ seconds.