Skip to content

Store handle of rmw_waitset_t in Executor - #166

Merged
jackieokay merged 1 commit into
masterfrom
waitset_handle
Jan 13, 2016
Merged

jackieokay merged 1 commit into
masterfrom
waitset_handle

Conversation

@jackieokay

Copy link
Copy Markdown
Contributor

Connects to ros2/rmw#49

TODO:

  • Expose max_conditions argument to the user-facing API in a graceful way.
  • Synchronization.

@jackieokay jackieokay added the in progress Actively being worked on (Kanban column) label Dec 2, 2015
Comment thread rclcpp/src/rclcpp/executor.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this function fail (return nullptr)? Should its value be checked in the constructor?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rmw_create_guard_condition can also return nullptr.

I will change the constructor to check both values and throw an exception if it either is null.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's a good point.

@dirk-thomas

Copy link
Copy Markdown
Member

I just committed a simpler condition - same as a few lines above.

@wjwwood

wjwwood commented Dec 2, 2015

Copy link
Copy Markdown
Member

I know it's not in review yet, but the changes so far lgtm now.

@jackieokay

Copy link
Copy Markdown
Contributor Author

with regards to exposing the max_conditions variable, I'm thinking this is a good time to add an ExecutorArgs struct to pass as the single argument to the constructor of Executor (and a default factory function).

Alternatively I could make the max_conditions variable an argument to MemoryStrategy and read it out of the MemoryStrategy when constructing the rmw_waitset, which makes more sense conceptually (max_conditions specifies a limit on allocation) but is more indirect in the implementation.

@jackieokay

Copy link
Copy Markdown
Contributor Author

On synchronization:

I made a test case for these changes in branch waitset_handle of system_tests to test 2 executors spinning in separate threads. Predictably, the test case segfaults occasionally (after ~50-100 iterations) on detach_condition, because the two threads share the global interrupt guard condition handle.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5d445a0 in c_iterTake () from /usr/lib/libddskernel.so
(gdb) bt
#0  0x00007ffff5d445a0 in c_iterTake () from /usr/lib/libddskernel.so
#1  0x00007ffff5cbc3e5 in _ConditionRemoveWaitset () from /usr/lib/libddskernel.so
#2  0x00007ffff5c9ca1d in gapi_waitSet_detach_condition () from /usr/lib/libddskernel.so
#3  0x00007ffff7bc0ab6 in atexit_t::~atexit_t (this=0x7fffffffd150, __in_chrg=<optimized out>)
    at /home/jackie/code/ros2_ws/src/ros2/rmw_opensplice/rmw_opensplice_cpp/src/rmw_wait.cpp:94
#4  0x00007ffff7bc175a in rmw_wait (subscriptions=0x7fffffffd2f0, guard_conditions=0x7fffffffd320, 
    services=0x7fffffffd300, clients=0x7fffffffd310, waitset=0x7e19fa0, wait_timeout=0x7fffffffd330)
    at /home/jackie/code/ros2_ws/src/ros2/rmw_opensplice/rmw_opensplice_cpp/src/rmw_wait.cpp:325
#5  0x00007ffff6f25614 in rclcpp::executor::Executor::wait_for_work (this=0x7fffffffd520, timeout=...)
    at /home/jackie/code/ros2_ws/src/ros2/rclcpp/rclcpp/src/rclcpp/executor.cpp:397

There are a few possible ways of fixing this:

  1. Make rmw_wait single-threaded using a global mutex. This is really inefficient and I'd prefer not to do it.
  2. Make attaching/detaching conditions to the waitset globally single-threaded using atomics in rmw, which is slightly less inefficient and more complicated to implement.
  3. Only attach/detach the global interrupt guard condition to the waitset once per Executor (in constructor and destructor). We would also have to disallow concurrent construction/destruction of Executors, and we would also have to enforce that a node can only belong to one Executor. We would also have to figure out a way to ignore detaching the global interrupt guard condition in rmw_wait, which could be tricky.

@jackieokay

Copy link
Copy Markdown
Contributor Author

I tried implementing approach 3 as described above to synchronizing access to the shared guard condition and it fixes the segfault in the multiple executors test case. I still haven't done anything to synchronize Executor construction/destruction.

@jackieokay
jackieokay force-pushed the waitset_handle branch 4 times, most recently from af90d26 to f3ed253 Compare December 4, 2015 23:28
@jackieokay
jackieokay force-pushed the waitset_handle branch 5 times, most recently from 9aabd0f to 1c6fbbb Compare December 18, 2015 19:46
Comment thread rclcpp/include/rclcpp/executor.hpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment or no comment 😉

jackieokay added a commit that referenced this pull request Jan 13, 2016
Store handle of rmw_waitset_t in Executor
@jackieokay
jackieokay merged commit 9d754a7 into master Jan 13, 2016
@jackieokay
jackieokay deleted the waitset_handle branch January 13, 2016 01:46
@jackieokay jackieokay removed the in progress Actively being worked on (Kanban column) label Jan 13, 2016
nnmm pushed a commit to ApexAI/rclcpp that referenced this pull request Jul 9, 2022
* started implementing the publisher test

* Working on tests for services

* Add basic subscription test

* Add check for nullptr as service impl.

* Add client test

* Undid accidental removal of null topic test

* Made subscription test consistent with the others

* Addressed comments from @mikaelarguedas, as well as made things more uniform.

* Replace EXPECT_EQ(-, false) with EXPECT_FALSE(-) (and analogous), as well as fixed typo in comment.

* Added check for init's return value.

* Added RCL_PUBLIC to export dll targets.

* nit: homogenize docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants