Boost logo

Boost Users :

Subject: Re: [Boost-users] scoped_lock
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2009-05-22 01:40:03


2009/5/21 Space Ship Traveller <space.ship.traveller_at_[hidden]>:
> {
> // Enqueue the notification to be processed
> scoped_lock(m_notifications.lock);
> m_notifications.sources->push(note);
> }
> Am I correct in assuming this is not going to work as expected? The compiler
> might not even instantiate the lock given this code?
>

Well, it will instantiate the temporary object, and probably won't
optimize it out since it's non-trivial, but it disappears "at" the
semicolon that ends the statement, so it doesn't do anything useful.

I think it would actually work to do this:

    scoped_lock(m_notifications.lock), m_notifications.sources->push(note);

But the way with the named object is the canonical way, so you really
should use it instead.

HTH,
~ Scott


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net