Boost logo

Boost :

Subject: Re: [boost] [thread] thread_specific_ptr performance
From: strasser_at_[hidden]
Date: 2010-01-12 12:21:02


Zitat von Peter Dimov <pdimov_at_[hidden]>:

> Stefan's idea was to reuse slots in the vector. This would avoid
> reallocation when keys are created and destroyed at the same rate.
> Unfortunately, on second thought, this isn't as straightforward as
> it seemed; threads could still hold non-NULL pointers when the key
> is destroyed.
>
> pthread_key_delete simply discards these non-NULL pointers without
> cleaning them up; the current implementation performs proper cleanup
> when the threads end.

so the current implementation destroys the thread specific objects on
thread exit even though the thread specific pointer it belonged to was
destroyed before?

I guess this was the reason to introduce a "key" in the first place? a
similar behaviour could be implemented using the vector-technique. the
key would have to be stored in the vector at the allocated index along
with the pointer so thread_specific_ptr::get() can decide if the
pointer is left-over from a previous thread_specific_ptr or an actual
pointer belonging to this thread_specific_ptr, and reset() can destroy
it.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk