Boost logo

Boost Users :

Subject: Re: [Boost-users] How can I have an object-specific and thread-specific pointer?
From: Phillip Hellewell (sshock_at_[hidden])
Date: 2011-11-19 00:58:38


On Fri, Nov 18, 2011 at 6:44 AM, Arun Ramasamy
<aramasamy_at_[hidden]> wrote:
> class MyClass{
>    thread_specific_ptr<MyCacheType> cacheptr;
> public:
>    MyClass(){
>
>    }
>    function_that_deals_with_thspptr(){
>        cacheptr.reset(new MyCacheType());//alloc thread specific memory;
>        //use the memory
>        .........
>        cacheptr.reset(0);//dealloc thread specific memory;
>    }
> };

No, actually it's more like this:

function_that_deals_with_thspptr()
{
    if( !cacheptr.get() )
    {
        cacheptr.reset(new MyCacheType());//alloc thread specific memory;
    }
    //use *cacheptr
    .........
    //there is no reset here
}

> Do you not know when the need for cacheptr ends?

No, because it should stick around to be reused until the MyClass
object goes away or the thread it goes with goes away.

Phillip


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