Closed pdima closed 5 years ago
I cannot reproduce this issue with 2.9 and the gnulinux target.
With https://github.com/orocos-toolchain/rtt/commit/58cb4bb733fc14de0ca520620cfcb689e2155797 it should not be possible to destroy an Activity
instance before the underlying thread is terminated. Before 2.9 the thread function was implemented in the RTT::os::Thread
class and it was only the ~Thread
destructor that joined after the Activity subclass has already been destroyed.
I see that there might be issues if setActivity()
would be called from the thread to be destroyed itself. Not sure if this is properly caught. But that does not seem to be the case in your example. Which thread executes the stop, configure, start operations? The TaskBrowser? Or a script running in the scripting service of exactly the component in question?
If there is no need to recreate the activity because only the periodicity changed, prefer setPeriod()
instead, which works even while the activity is running.
I found task.stop(); task.configure(); task.start(); sequence is called in client thread as OwnThread operation. It works fine when ClientThread used.
Is it acceptable to change activity during configureHook? I tried to apply priority and scheduler from properties/configuration not available at construction time.
Is it acceptable to change activity during configureHook? I tried to apply priority and scheduler from properties/configuration not available at construction time.
In general it is okay to set the component's activity in the configureHook(), but only if it is called from an external thread, not from the thread running the component itself (like in an OwnThread operation). Usually this external thread is the main thread and configure()
is called during deployment.
You can modify all relevant properties of an existing activity in configureHook(), while the thread is running without having to destroy the activity:
RTT::TaskContext *tc = this;
tc->setPeriod(new_period);
RTT::os::ThreadInterface *thread = tc->getActivity()->thread();
if (thread) {
thread->setScheduler(sched_type);
thread->setPriority(priority);
}
Note that not every activity has its own thread and a thread might be reused by multiple activities for certain activity types. At the moment getActivity()->thread()
always returns the main thread in case there is no thread associated to the activity, but I am going to change that for 2.9. For the standard Activity
there are no issues and the code snippet above should just do what you would expect.
I have a task with periodic activity created in updateHook():
It always segfaults, looks like the activity loop continues to use the old activity data, deleted when the new Activity created. I tested with the current toolchain 2.9, but can reproduce the it with older versions as well.
Valgrind output: