eclipse-iceoryx / eclipse-iceoryx/iceoryx

POSIX wrapper for pthreads

Open
#1,365 1 comment 0 reactions 1 assignee Claimed by @FerdinandSpitzschnueffler View on GitHub
enhancement globex refactoring
Dominant language
C++
Stars
2.2k
Forks
492
Avg merge
18h 57m
Merged PRs (30d)
1

Description

## 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
* [ ] remove free functions `setThreadName` and `getThreadName`

## 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.