Let's say that we have initialized 2 different nodes
inside 2 different main
functions. Also assume that each of these two nodes have one subscriber
each, subscribing to the topic topic_a
. We also have ros::Spin()
at the end of each of these 2 main
functions.
In ROS 1, there is a 1-to-1 correspondence between nodes and processes.
So only a single node can "live" in a specific process (or: program).
Programs do not share any of their internal state by default, which would include any (global) variables.
You also -- by default -- cannot have "two different main
functions" in a single program. The compiler will not allow you.
In my answer below I've assumed that "two different main
functions" therefore means: "two different programs".
Would the callbacks
corresponding to each of these 2 subscribers be pushed to the same global queue
and ros::spin()
call from either of the 2 nodes would spin
the oldest callback from this queue
?
Due to the way operating systems isolate processes from each other, it's impossible for two nodes to share a single callback queue (or to share anything of their internal state really).
In the end, this is not really a "ROS question". Distilling it down to its essence, you ask whether process_A
can access internal state of process_B
. For any modern operating system, and without using special "tricks" (ie: shared memory), the answer will always be: no.
After posting an answer I must say this sounds a lot like a question on an exam, or as part of someone's homework.
@gvdhoorn I need more time.