Open liuzf1988 opened 1 year ago
We don't have plans to implement such a multithreading mechanism in dora right now. The main advantage of the current single-threaded design is that the on_input
function has exclusive access to the operator's fields (when using the Rust or C++ APIs) or the custom operator_context
(when using the C API).
If you want to handle inputs in different threads, you can spawn the handler threads manually and e.g. use a go-style channel to forward the relevant inputs. I'm not familiar with the C++ ecosystem, but the ahorn/cpp-channel seems to implement something like this. Your on_input
method would then just match on the id
and forward the input to the respective handler thread. Instead of OS-level threads, you should also be able to use C++20 coroutines or some other type of green threads.
This is a problem encountered in porting NDT algorithm from ROS2 ecosystem to DORA framework
In ROS2, the
ndt_scan_matcher
package adopts the multithreading mechanism: from its code, it can be seen that, the two callback functions (callbackMapPoints
andcallbackSensorPoints
) and theserviceNDTAlign
service share a thread, which are directly related to the setting and execution of the NDT algorithm, whileCallbackInitialPose
is a separate thread. Extract the relevant codes as follows:During the migration of NDT algorithm to DORA framework. The
on_input
function is temporarily implemented as follows:How to implement multithreading mechanism in DORA operator?