asked 2012-02-24 00:50:31 -0500Conrado Miranda
I've been using ROS for a while and I just faced a possible bug. A service is called about the same time a topic got published and that topic is subscribed by the same node that implements the server.
When they run, I get a race condition, as they both use the same variable. Is it expected? I'm using python.
An example of output would be
0 1 [0.2, 0.2] 2 3 4
The list is printed inside callback for the topic and the sequence of numbers is called in the callback for the service. The service is filling the list accessed. I should be able to provide some code quite soon, as my priority is to get this working and later look for the reason (will use mutex for now).
There is no guarantee in ROS that callbacks are not executed in parallel. This is desired behavior. If you want to avoid this kind of race condition, you need to use locks in your program code, i.e. when entering a callback a lock is acquired and when returning the lock is released again. That way, you get exclusive execution of callbacks. For python, you can use the threading.Lock class (tutorial). For C++ I suggest to use boost::scoped_lock.
Asked: 2012-02-24 00:50:31 -0500
Seen: 300 times
Last updated: Feb 24 '12