Subject: Re: [boost] [thread] TSS cleanup
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-09-22 12:05:58
"Felipe Magno de Almeida" <felipe.m.almeida_at_[hidden]> writes:
> I would like to know if the storage created for
> boost::thread_specific_ptr in the tss
> specific code for win32 is free'd after the destruction of said
> boost::thread_specific_ptr, or
> if it stays until the end of the process.
Storage is allocated on a per-thread basis, and freed when the thread exits.
> For example:
> for(int i = very_big_number;i--;i > 0)
> boost::thread_specific_ptr<int> p(new int);
> To my knowledge, the pointer returned by new in this case is freed.
> But does the int* that is created to store the pointer to new int is also
> freed, or this program will get only bigger and bigger?
As written this code is fine: it will reuse the same slot since p will
have the same address each time through, and it uses the address as
the key. It is undefined behaviour if other threads can still try and
access a given thread_specific_ptr (including having data stored
associated with it) after it has been destroyed.
If you create and destroy thread_specific_ptr instances all over the
place then in general this will increase the list for each thread that
accesses the tsp. It shouldn't be too hard to have the TSS entry be
removed from the list when it is no longer needed. I'll try and get
round to sorting it for Boost 1.37. If you raise a trac ticket I'll be
more likely to remember.
-- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk