-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve support for c++ threading and synchronization #735
improve support for c++ threading and synchronization #735
Conversation
194035e
to
11c3edb
Compare
This was considerably easier with the |
c53bdb4
to
cb6f07e
Compare
694e91d
to
0706d26
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
This comment has been minimized.
This comment has been minimized.
0706d26
to
b32e55d
Compare
|
1800fde
to
f167e82
Compare
This can probably be opened for review at this point. Likely I should make PRs for submodules too. |
f167e82
to
775f79d
Compare
Two additional patches needed diff --git a/libgcc/gthr-c11.h b/libgcc/gthr-c11.h
index 3cadb110d96..db2cc7a46f7 100644
--- a/libgcc/gthr-c11.h
+++ b/libgcc/gthr-c11.h
@@ -45,6 +45,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define _GTHREAD_USE_COND_INIT_FUNC 1
#define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function
+#define _GLIBCXX_THREAD_ABI_COMPAT 1
+#define _GLIBCXX_HAS_GTHREADS 1
+#define _GLIBCXX_USE_THRD_SLEEP 1
+
#include <threads.h>
#include <time.h>
Include the header for diff --git a/libstdc++-v3/include/bits/std_thread.h b/libstdc++-v3/include/bits/std_thread.h
index dd625de3bc3..413ad4c9e09 100644
--- a/libstdc++-v3/include/bits/std_thread.h
+++ b/libstdc++-v3/include/bits/std_thread.h
@@ -41,6 +41,7 @@
#include <bits/invoke.h> // std::__invoke
#include <bits/refwrap.h> // not required, but helpful to users
#include <bits/unique_ptr.h> // std::unique_ptr
+#include <bits/shared_ptr.h> // std::shared_ptr
#ifdef _GLIBCXX_HAS_GTHREADS
# include <bits/gthr.h> |
775f79d
to
c2c9e86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haven't been able to review the submodule changes but the configs changes look good
@dkalowsk - I still need to make an |
cc @XenulsWatching |
The one oddity I found with using the C11 threads API to provide the C++11 threads API was that there is no equivalent for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
DNM until the submodule refs are updated.
@cfriedt Could you please rebase and update the submodule modules to point to the merged commits? |
c2c9e86
to
947d2e9
Compare
@stephanosio - should be updated now. |
Add support for ISO C++11 threads, mutexes, condition variables, semaphores, locks, scoped locks, synchronized streams, and futures (async programming) via ISO C11 threads. Signed-off-by: Christopher Friedt <[email protected]>
947d2e9
to
166747d
Compare
Overview
This change allows Zephyr developers to use most or all of the C++ facilities in gcc that depend on gthread support.
Those facilities include (but are likely not limited to)
std::thread
std::this_thread
std::mutex
std::recursive_mutex
std::shared_mutex
std::condition_variable
std::binary_semaphore
std::counting_semaphore
std::lock_guard
std::unique_lock
std::scoped_lock
std::shared_lock
std::syncstream
std::future
std::async
Associated Zephyr SDK PRs
Associated Zephyr PRs
Zephyr SDK Toolchain Snapshots
* The riscv64-zephyr-elf toolchain stack unwinding support is not used in Zephyr. This should be fixed by zephyrproject/zephyr#69912.
Testing branch
Test are in review at zephyrproject-rtos/zephyr#43729 .
The test suites can be run with e.g.
They should run via picolibc eventually as well, but IIRC, there is an error about a missing
.spec
file.Help Wanted
Updating Picolibc
The few changes required to newlib might also need to be applied to picolibc in order to expose similar functionality.
Additional Testsuites
It would be helpful to add test suites for the following
std::semaphore
std::future
std::coroutine
Additional testsuites can be added in parallel. They should not be considered blockers by any means, since they do not specifically depend on anything specific to Zephyr.
Technically, not dependent on threading, coroutine support in Zephyr might Just Work (TM). However, coroutines have the potential to be extremely impactful in Zephyr as they are far more memory efficient than threads (important for resource-constrained devices).
Building, Testing, and Uploading Additional SDK Toolchains
"Zephyr SDK Toolchain Snapshots" lists a number of unchecked boxes and unlinked toolchains without links. To check the box and populate the link, the following steps should be taken:
LLVM Toolchain Integration
Currently, all of this work is being done against Zephyr's GCC-based SDK toolchains. It's possible that LLVM toolchain integration will be much easier.
Our testsuites should run successfully with both GCC-based toolchains as well as with LLVM.