Boost logo

Boost :

Subject: Re: [boost] [Review.Coroutine] Some comments
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-09-09 03:24:50


Le 08/09/12 22:15, Oliver Kowalke a écrit :
> Am 08.09.2012 21:57, schrieb Vicente J. Botet Escriba:
>>
>> The suggested Allocator is just there to responds to your need
>> (predictability) :)
> Vicente - I looked at packaged_task as you suggested. I found
> following code:
>
> packaged_task() : {
> typedef typename Allocator::template rebind<detail::task_object<R,FR>
> >::other A2;
> A2 a2(a); // allocated on the stack, after return from ctor destroyed
> typedef thread_detail::allocator_destructor<A2> D;
> task = task_ptr(::new(a2.allocate(1)) detail::task_object<R,FR>(f),
> D(a2, 1) ); // a2 passed to allocator_destructor
> }
>
> template <class _Alloc>
> class allocator_destructor
> {
> ...
> _Alloc& alloc_; // reference to A2
> size_type s_;
> public:
> allocator_destructor(_Alloc& a, size_type s)BOOST_NOEXCEPT
> : alloc_(a), s_(s)
> {}
> ...
> };
>
> allocator_destructor hold only a reference to the allocator A2 but the
> instance was allocated on the stack.
> Doesn't this mean that the alloc_ member of allocator_destructor will
> point to a non-existing object?
>

Yes, you are right. The code is using something not very clean that
works only for stateless allocators.
I guess that storing the allocator on allocator_destructor should solve
the issue.
Please could you create a ticket to track the issue?

Best,
Vicente


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