[PATCH 1/2] librtemsc++: Add join() and detach() to the thread

Gedare Bloom gedare at rtems.org
Thu Oct 8 16:28:45 UTC 2020


On Thu, Oct 8, 2020 at 2:19 AM <chrisj at rtems.org> wrote:
>
> 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())
explicit { for 1-liners is preferred
> +        system_error_check (ENOMEM, "join");
}

In general, this file is not entirely adhering to RTEMS coding style.
What coding style is it? Sorry I missed this in the first patch(es)
adding the cxx iface

> +      system_error_check (::pthread_join (id_.id_, nullptr), "join");
prefer to not have a space before the ( for function calls so that
function-like macros appear consistently

> +      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, &param),
> --
> 2.24.1
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list