Skip to content

Commit 66b259e

Browse files
committed
Issue #15: rxros::spin() funtion uses unnecessary many threads
1 parent 0a63e65 commit 66b259e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,18 @@ The other purpose of the rxros::spin function is to dispatch messages from ROS t
163163
Failure to omit the rxros::spin function will cause the program to terminate immediately and observables based on ROS topics
164164
will not emit any events.
165165

166+
rxros::spin will per default use one thread for dispatching messages. For most nodes this will be sufficient.
167+
In special cases where a node uses many topics it may be necessary to use more threads for dispatching messages.
168+
This can be achieved by specifying the number of threads the rxros::spin function should use.
169+
A special case is rxros::spin(0) which will allocate a thread for each CPU core.
170+
166171
The Example below shows a minimal RxROS program that creates a ROS node named “my_node”.
167172
The program will due to rxros:spin() continue to run until it is either shutdown or terminated.
168173

169174
### Syntax
170175

171176
```cpp
172-
void rxros::spin();
177+
void rxros::spin(uint32_t thread_count = 1);
173178
```
174179
175180
### Example

rxros/include/rxros/rxros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ namespace rxros
4848
ros::init(argc, argv, name);
4949
}
5050

51-
static void spin() {
52-
ros::MultiThreadedSpinner spinner(0); // Use a spinner for each available CPU core
51+
static void spin(uint32_t thread_count = 1) { // Use per default 1 thread for spinning
52+
ros::MultiThreadedSpinner spinner(thread_count);
5353
spinner.spin();
5454
}
5555

0 commit comments

Comments
 (0)