Boost logo

Boost Users :

Subject: Re: [Boost-users] How to call destructor on thread object?
From: Lane (software.research.development_at_[hidden])
Date: 2015-05-19 16:40:09


Thanks for the explanation, that helps. But what I'm looking to do is find
a way to call the destructor on the thread object. The ClassA and classB
objects are connected to a USB device and I need to find a way to properly
shut them down before destroying the threads in on_exit(). Any thoughts?

On Tue, May 19, 2015 at 12:49 AM, Gavin Lambert <gavinl_at_[hidden]>
wrote:

> Mere moments ago, quoth I:
>
>> On 19/05/2015 15:26, Lane wrote:
>>
>>>
>>> I'm using the boost meta state machine and upon entry of this state, I
>>> create two threads, and stop these threads in the on_exit().
>>>
>>> In on_entry(), I call the functors of each class and create threads and
>>> add those to a boost thread_group. What I need to do now is call the
>>> destructor of the objects on the threads ( of ClassA and ClassB) within
>>> on_exit(). I'm unclear as to how the destructors of the objects
>>> would/should be called when interrupting the threads. The destructors
>>> are currently not being called.
>>>
>>
>> Since you are passing a copy of the object as the thread's state, the
>> destructor for the local instances will be called in on_entry(), and the
>> destructor for the instances owned by the thread will be called when the
>> thread_group is destroyed, which is when MyEvent is destroyed.
>>
>> I'm not really familiar enough with Boost.MSM to know whether the event
>> instance is destroyed when the event is handled (which if this were the
>> case, you shouldn't be keeping threads in it), or when the containing
>> state machine is destroyed, or only when the program exits.
>>
>
> Sorry, pressed Send too quickly.
>
> If you want to destroy the threads in on_exit instead, then since
> thread_group lacks a means to remove a thread (unless you still have a
> reference to it), you will have to destroy the thread_group instead.
>
> The simplest way to do that is to wrap it in a std::unique_ptr and reset()
> it in on_exit.
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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