iceoryx
iceoryx copied to clipboard
POSIX wrapper for pthreads
Brief feature description
We need a POSIX wrapper for pthreads
to get rid of exceptions and undefined behavior.
For posix platforms the wrapper shall support:
- Set stack address
- https://man7.org/linux/man-pages/man3/pthread_attr_setstack.3.html
- consider suggestions in #1400
- Setting scheduler priority
- https://man7.org/linux/man-pages/man3/pthread_setschedprio.3.html
- Set CPU affinity
- https://man7.org/linux/man-pages/man3/pthread_setaffinity_np.3.html
- Set stack size
- See, https://man7.org/linux/man-pages/man3/pthread_attr_setstack.3.html
- https://man7.org/linux/man-pages/man3/pthread_attr_setstacksize.3.html
- The destructor shall call join by default, see
std::jthread
https://en.cppreference.com/w/cpp/thread/jthread - Explicit thread termination:
- https://man7.org/linux/man-pages/man3/pthread_exit.3.html
Optionally, it would be awesome when it supports
- https://man7.org/linux/man-pages/man3/pthread_equal.3.html
- https://man7.org/linux/man-pages/man3/pthread_self.3.html
- Set the scheduler
- https://man7.org/linux/man-pages/man3/pthread_attr_setschedparam.3.html
- Set contention scope:
- https://man7.org/linux/man-pages/man3/pthread_attr_setscope.3.html
- Set cleanup handlers
- https://man7.org/linux/man-pages/man3/pthread_cleanup_push.3.html
Tasks
- [x] implement Thread class with minimal functionality needed for current code base
- [x] make it work on Windows and Mac
- [ ] replace all
std::thread
occurrences - [ ] implement must have features
- [ ] add awesome optional features
Design considerations
- pass an optional to create method
- current state
- https://github.com/eclipse-iceoryx/iceoryx/pull/1400#discussion_r903375242
- or separate handle and storage
- proposed API: https://github.com/eclipse-iceoryx/iceoryx/pull/1400#discussion_r899220308
- optional: potential to forget reset on an early return, https://github.com/eclipse-iceoryx/iceoryx/pull/1400#discussion_r898375219
- https://github.com/eclipse-iceoryx/iceoryx/pull/1400#discussion_r906079855
- callable with generic signature?
- can be achieved with a lambda capturing the needed arguments in the current implementation
- see also https://github.com/eclipse-iceoryx/iceoryx/pull/1400#discussion_r899256494
- movable threads?
- https://github.com/eclipse-iceoryx/iceoryx/pull/1400#discussion_r898890414
- easier if thread handle and storage are separated
@FerdinandSpitzschnueffler since we cannot use the heap I think setting the stack address is more of a must have than a nice to have.