[PATCH 1/2] librtemsc++: Add join() and detach() to the thread
chrisj at rtems.org
chrisj at rtems.org
Thu Oct 8 08:19:33 UTC 2020
From: Chris Johns <chrisj at rtems.org>
- Do not start threads detached
---
cpukit/include/rtems/thread.hpp | 4 ++++
cpukit/librtemscxx/thread.cpp | 22 ++++++++++++++++++----
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/cpukit/include/rtems/thread.hpp b/cpukit/include/rtems/thread.hpp
index e90e664dfa..2c4899dc0b 100644
--- a/cpukit/include/rtems/thread.hpp
+++ b/cpukit/include/rtems/thread.hpp
@@ -321,6 +321,10 @@ namespace rtems
bool joinable() const noexcept;
+ void join() noexcept;
+
+ void detach() noexcept;
+
/*
* Constrain use. These are not available.
*/
diff --git a/cpukit/librtemscxx/thread.cpp b/cpukit/librtemscxx/thread.cpp
index 11bf3df230..ae13201bd4 100644
--- a/cpukit/librtemscxx/thread.cpp
+++ b/cpukit/librtemscxx/thread.cpp
@@ -346,6 +346,24 @@ namespace rtems
return !(id_ == id());
}
+ void
+ thread::join() noexcept
+ {
+ if (!joinable())
+ system_error_check (ENOMEM, "join");
+ system_error_check (::pthread_join (id_.id_, nullptr), "join");
+ id_ = id();
+ }
+
+ void
+ thread::detach() noexcept
+ {
+ if (!joinable())
+ system_error_check (EINVAL, "detach");
+ system_error_check (::pthread_detach (id_.id_), "detach");
+ id_ = id();
+ }
+
thread::state_base::~state_base () = default;
void
@@ -358,10 +376,6 @@ namespace rtems
system_error_check (::pthread_attr_init (&pattr),
"attribute init");
- system_error_check (::pthread_attr_setdetachstate (&pattr,
- PTHREAD_CREATE_DETACHED),
- "set detached state");
-
struct sched_param param;
param.sched_priority = attr.get_priority ();
system_error_check (::pthread_attr_setschedparam (&pattr, ¶m),
--
2.24.1
More information about the devel
mailing list