Hi,
I tried to make a master-slave component to get stuck in a deadlock.
My setups is as follows:
I have a master component that triggers slaveA and slaveB in its own
updateHook() by calling update() on them in the given order:
master::updateHook(){
slaveA_ptr->update();
slaveB_ptr->update();
}
The slave components have an operation to be executed in their OwnThread.
When slaveA calls in its updateHook() the OwnThread operation on slaveB,
I expect this to cause a deadlock since slaveB will execute the
operation only when its execution engine is triggered,
which is done by the master, only when the updateHook() of A returns...
When all my components are simple components written in C++, Orocos
warns me of a possible deadlock and does not allow me to use this code:
0.114 [ ERROR ][rttlua-gnulinux::main()] You're using call() an
OwnThread operation or collect() on a sent operation without setting a
caller in the OperationCaller. This often causes deadlocks.
0.114 [ ERROR ][rttlua-gnulinux::main()] Use this->engine() in a
component or GlobalEngine::Instance() in a non-component function.
Returning a CollectFailure.
0.114 [ ERROR ][rttlua-gnulinux::main()] in updateHook(): switching to
exception state because of unhandled exception
However, when my slaveA is written in Lua:
comp_str=[[
i=0
function startHook()
i=0
return true
end
function updateHook()
i=i+1
print(rtt.getTC():getName().." executes updateHook !")
rtt.getTC():getPeer("slaveB"):getOperation("ownthread_operation")()
end
function stopHook()
print(rtt.getTC():getName().." updateHook executed
"..tostring(i).." times")
end
]]
dp:loadComponent("slaveA", "OCL::LuaComponent")
slaveA=dp:getPeer("slaveA")
dp:setMasterSlaveActivity("master", "slaveA")
slaveA:exec_str(comp_str)
slaveA:addPeer(slaveB)
slaveA:configure()
slaveA:start()
There is no error, and actually, the whole setup runs fine.
How can this actually happen? I see that it unlikely for Orocos to catch
the situation,
but why doesn't it cause a deadlock?
(The relevance of this example is that in legacy code, there are many
supervisors written in Lua that call operations on components...)
Nick