0

I have the following code: where m_event is a boost::condition_variable

        boost::scoped_lock dummy;
        boost::unique_lock<boost::scoped_lock> lock(dummy); // TODO: see if dummy is correct
        m_event.wait(lock, [this] () {
            return !this ->m_enqueue.empty();
        });

I don't really need that dummy locker I just want the event to stop upon a certain boolean condition, do I not understand something?

Why am I forced to use the dummy lock?

(P.S. code works great..)

EDIT: In fact if I understood correctly, what I have in my class is a boost::mutex, let's call it m_mtx and obvious inserters to the m_enqueue.. so I am changing my implementation accordingly to the lock to lock on m_lock and then the inserters would only do:

boost::mutex::scoped_lock<boost::mutex> guard(m_lock);

make sense?

Alon
  • 1,776
  • 13
  • 31
  • See [this previous answer](http://stackoverflow.com/questions/13099660/c11-why-does-stdcondition-variable-use-stdunique-lock) – ichramm Jan 12 '14 at 18:19
  • @ichramm: That's a question! And [it's a subtly different one](http://stackoverflow.com/questions/13099660/c11-why-does-stdcondition-variable-use-stdunique-lock#comment17804829_13099660), at that... – Lightness Races in Orbit Jan 12 '14 at 18:22

1 Answers1

0

timed_wait waits for a lock to be obtained, if it does so in time.

Without a lock, it can't do anything.

It seems to me you're abusing timed_wait.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055