Repository navigation
Use global WaitSet to be reused in rmw_wait - #96
jackieokay wants to merge 1 commit into
Conversation
|
Please do not use a global variable. Instead rmw_init() needs to return a handle where each rmw impl. can embed custom information (similar to |
|
alright, before I implement that for Opensplice and Connext, here's an outline of the approach: In So, rclcpp and other rcl implementations have to store the handle somewhere (probably in Executor or context). |
|
I don't think having If we want to be able to call If we want to say that Our decision on this matters to me since it is reflected in the |
|
@wjwwood Why can Also depending on the rmw impl. there is no reason to prevent someone to juggle to rmw instances at the same time if their state is fully encapsulated in these handles (rather then using global variables). @jacquelinekay As William mentioned the struct should also contain an identifier (like the other struct) to ensure the the same rmw impl. is handling it. Eventually the handle should be passed to many if not all functions. To avoid requiring to pass multiple "handles" to some functions more specific structs like the node handle could reference the generic one. Then only the most specific handle need to be passed. |
|
I'd like to echo @dirk-thomas 's comment about the multiple rmw instances use case. While it seems unlikely to me that someone would want to use two DDS implementations at the same time, the idea that something other than DDS can provide an rmw implementation has been promoted quite a bit. If I have a pure TCP implementation, a DDS implementation, and (the stuff of nightmares) a CORBA implementation, then I should be able to use them all from within a single node if my system designer or my deployer says that is what is needed. Also, perhaps, two instances of a statically (compile-time) configurable DDS implementation? I'm not sure such a thing exists, but if it does then the deployer should have the option of using both simultaneously. If the above use cases can be supported using global variables then great, but if not then I back the choice of encapsulating state in handles. |
|
I don't see a compelling reason to redesign the @gbiggs To be clear @dirk-thomas is not talking about having different rmw implementations being run simultaneously, just multiple instances of the same rmw implementation. I think the more immediate question is whether to allow |
|
@wjwwood Thanks for the clarification. Your argument makes more sense now. I think that being able to have multiple instances of the same rmw implementation could be useful in some corner cases but if it requires both API and implementation changes then it doesn't seem worth the effort. Which means hiding stuff in an inaccessible global variable is not that bad. |
|
I agree that it adds unnecessary complexity to support immediately subsequent calls to rmw_init (perhaps from different threads) that instantiate different instances of rmw. On a different note, I do think there is a compelling argument to have access to the rmw state that is implicitly instantiated by the library (the state that Dirk proposed to encapsulate in a handle) or at least pass argument to it on initialization. For example, I'd like the user to have the ability to preallocate the ConditionSeq object in rmw_wait with the maximum number of conditions that rmw could respond to. I think this quantity is general enough to expose to the rmw interface. The alternative would be to hardcode an arbitrary value, which I find very unappealing. |
|
I'd be fine having |
Exposing the state in a handle is fine, but we have to be careful to not expose the DDS symbols across the Then any other implementations would have to work within that constraint. |
|
Ok, I'm going to save the work we've discussed on We should address the more immediate question that @wjwwood brought up in his previous post: if multiple threads in the same process can enter In the current implementation, if two threads try to wait on the same entity (subscription/client/service) at the same time, I believe they will both try to execute the same entity twice, which is a bug (though this is not possible in rclcpp because we don't allow multiple threads to spin at once, and rmw_wait is only called in spin* functions). But if there are two nodes executing in the same process, perhaps they should be able to enter rmw_wait at the same time, since they do not share instances of subscriptions/clients/services. This would be a compelling reason to have two Executors, to simplify the logic for separating the execution and execution state of the two nodes, while still having one intra-process manager to handle the intra-process messaging between the nodes. In this case, I think each Executor would need its own rmw "context" or "handle". The question that remains for me is if this case is compelling enough to add more complexity to rmw. |
|
In the current state of the PR the error handling is completely broken since the now global WaitSet keeps its state. For repeated invocations of rmw_wait it is not guaranteed that the WaitSet has no attached conditions before adding new ones. |
|
I detach the read_conditions and guard_conditions after calling WaitSet::wait in this PR: If you think this is broken, can you suggest an alternative way of detaching all conditions from the WaitSet? |
|
Any return statement in this function will prevent the WaitSet to be set back into a state where it doesn't have any conditions attached. |
|
The use case of having multiple executors in a single process is fairly important for us. It provides more flexibility to node management approaches than each process being restricted to a single executor would. How much complexity would it add to rmw? As far as I know, DDS itself shouldn't provide any roadblocks. |
|
Investigate whether DDS's wait call can be invoked from two separate threads and under what conditions (e.g., what elements can or cannot be shared across the two wait sets). Assuming that thread-safe waiting is fundamentally possible, then add APIs to rmw to create and destroy wait sets, passing back and forth handles to them, to be stored, for example, in an executor. |
|
Going to redo this in a forthcoming PR |
In progress. I'd appreciate some preliminary feedback on this approach.
TODO:
Global ConditionSeq to be used rmw_wait (with option to pre-allocate)
Matching updates to Connext
Should the global shared variables be initialized/de-initialized in rmw_init/rmw_shutdown?