Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2008-03-03 03:55:52


Andrey Semashev <andysem <at> mail.ru> writes:

>
> Hi, I have a couple of questions about thread_specific_ptr in 1.35.
>
> 1. I can see that there is an ability to set up a logic of reclaiming
> resources that thread_specific_ptr points to. Why is it limited (a) only
> to a pointer to function and (b) can only be set up in
> thread_specific_ptr's constructor? It might be better to provide
> interface similar to shared_ptr in this way?

a) The interface is how it was in boost 1.34 and prior. The underlying code
would allow something more general, but I haven't updated the interface for that
yet.

b) If it wasn't set up in the constructor, it would have to be set up with every
call to reset. There's arguments either way. This is the boost 1.34 (and prior)
way.

> BTW, I can see that
> although the cleanup function is required to receive T* as its argument,
> it is being passed void* in the run_custom_cleanup_function. Isn't an
> explicit cast required here?

Yes, you're right. I must have missed that when I copied into the boost tree,
and there wasn't a test for that in boost.

This is now issue 1665, which is fixed in version 43461 on trunk.

> 2. Why thread_specific_ptr isn't copyable? Why can't it share TLS keys
> (or whatever it uses to find the thread-specific resource) in the
> dynamically allocated cleanup object? I would expect
> thread_specific_ptr, being a pointer as its name implies, to be copyable.

Fundamentally, the TLS key is the instance of thread_specific_ptr itself, which
is therefore not transferable. If you could assign one instance to another, how
would that affect other threads that had values associated with the old value
stored in that instance? If you can't change an object after construction, why
do you need to copy it? You could just pass around a pointer or reference
instead.

Anthony

--
Anthony Williams
Just Software Solutions Ltd - 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