Boost logo

Boost Users :

Subject: Re: [Boost-users] Good lock_guard<mytype> example
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2013-04-01 21:20:46


On Mon, Apr 1, 2013 at 6:20 PM, John Rocha <jrr_at_[hidden]> wrote:

> Hello Michael,
>
> *this is a pointer to the mutex that the 'lock_guard' is using. The name
> "this" is unfortunate since it overlaps with an object's 'this' pointer...
> unless your class 'mytype' is derived from a mutex....
>

I believe just what I'm looking for. From a previous reply, I don't
"really" want to derive from lockable classes, I just want to guard this
class as a potentially thread-safe operation.

> I've usually seen it used on just a boost::mutex.
>
> boost::mutex the_lock;
>
>
> and later in some code associated with the lock, you could activate it in
> a block by doing;
>
> boost::lock_guard<boost::mutex> lock(the_lock);
> ...do stuff....
>
>
> Consider looking at:
> http://www.boost.org/doc/libs/1_53_0/doc/html/thread/synchronization.html#thread.synchronization.tutorialand searching for lock_guard I think it has a pretty decent example there.
>
>
>
> On 4/1/2013 4:12 PM, Michael Powell wrote:
>
> Hello,
>
> The pattern goes something like this: boost::lock_guard<mytype>
> guard(*this).
>
> However, compiler is asking for a lock or unlock. I don't know what this
> is, or what it should be.
>
> Thank you...
>
> Regards,
>
> Michael Powell
>
>
> _______________________________________________
> Boost-users mailing listBoost-users_at_[hidden]http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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