Boost logo

Boost Users :

Subject: Re: [Boost-users] seeking comments on 'weak_key_map' experiments
From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-12-12 13:02:40


Nicolas Lelong:

>> Does the weak_ptr need to be removed from the map "instantly" when it
>> expires?
>> Could you just clean up the expired weak_ptrs at some later point? For
>> example, when an iterator is incremented it might remove all the
>> weak_ptrs
>> it
>> encounters while it is trying to find the next live weak_ptr in the map.
>>
>
> In my current usage scenario and implementation, I rely on values being
> removed 'instantly'.
>
> The thing is that I never iterate these maps, I only query values
> associated
> to keys ; so in this case, a cleanup could be triggered, but it would
> increase the 'query' time cost - I tend to see this weak_key_map as a
> lightweight construction if possible...
>
> I also find that the 'instantly' matches well the shared_ptr philosophy,
> but
> that's not very objective.

Accessing unrelated objects on destruction/deletion does not quite fit the
shared_ptr/weak_ptr philosophy. This introduces data races and coupling and
locking issues in the presence of multiple threads. Having p.reset() in
thread A, who knows nothing about weak key maps, access a map object which
may well be in use at the moment in thread B, forces you to make your
container tolerate concurrent modification, preferably without using locks
(to avoid locking hierarchy violations).

--
Peter Dimov
http://www.pdplayer.com 

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