Can nodelet's onInit and callbacks be executed in parallel?
I have a problem where only sometimes one of my nodelets crashes on startup. I identified a possible issue in the order of commands in the onInit()
method. Consider the following:
void onInit() {
subscriber = getNodeHandle().subscribe("something", 100, &ThisNodelet::callback, this);
publishRate = getPrivateNodeHandle().param("publish_rate", 10.f);
}
void callback(someMessageType msg) {
if (publishRate == 10.0) { // publishRate maybe uninitialized?
...
}
}
My question is whether publishRate might be uninitialized when entering the callback, because it might be called right after the subscription happened, not only after onInit()
finished. This would be quite an important implication for the order in which to do things in the onInit()
method but I did not find documentation about this.
wiki/nodelet - Threading Model has some hints, but nothing explicit.
I think you can assume that callbacks for msgs will start to be processed as soon as you call
subscribe(..)
, sopublishRate
would indeed be uninitialised there.Btw: checking equality on float type variables is not really robust.
Yeah, this was just to do //something// with it. I would suggest to add that detail to the documentation then, it seems to be very easy to introduce bugs this way, esp. since it is somehow counter intuitive to have anything happen before an init function exits.
Well .. it's a wiki, so anyone can edit it. It would be great if you could add some additional detail there.
Note that this is most likely not specific to nodelets: any multi-threaded ROS node (fi:
AsyncSpinner
) would probably behave the same (but I haven't checked).I will do that, thanks for the information!