Boost logo

Boost Users :

Subject: Re: [Boost-users] valgrind reports memory still reachable when using shared_lock and shared_mutex
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-09-02 21:31:13


AMDG

Rajeev Rao wrote:
> When using shared_mutex class with shared_lock. I see the following behavior
>
> boost::shared_lock<boost::shared_mutex> lock(m_mutex) ;
>
> When running valgrind
>
> ==32255== LEAK SUMMARY:
> ==32255== definitely lost: 0 bytes in 0 blocks.
> ==32255== possibly lost: 0 bytes in 0 blocks.
> ==32255== still reachable: 8 bytes in 1 blocks.
> ==32255== suppressed: 0 bytes in 0 blocks.
>
> However, if I change the code
> to boost::shared_lock<boost::shared_mutex> lock(m_mutex,boost::adopt_lock) ;
> then the valgrind report goes away.

This is undefined behavior. From the documentation

shared_lock(Lockable & m,boost::adopt_lock_t)
Precondition:
    The current thread owns an exclusive lock on m.

> I understand that there are valid cases to expect reachable memory at exit Should this be expected in this case ?
>

Yes. This is not expected, and there is no obvious way to change it.

In Christ,
Steven Watanabe

P.S. Please start a new thread instead of replying to an unrelated
existing thread.


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