1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15
16 #include "pw_thread/thread.h"
17
18 namespace pw::thread {
19
20 // Creates a detached a thread of execution.
21 //
22 // This is a very simple helper wrapper around Thread to help the common case of
23 // creating a Thread which is immediately detached. For example instead of:
24 //
25 // Thread(options, foo).detach();
26 //
27 // You can instead use this helper wrapper to:
28 //
29 // DetachedThread(options, foo);
30 //
31 // The arguments are directly forwarded to the Thread constructor and ergo
32 // exactly match the Thread constuctor arguments for creating a thread of
33 // execution.
34 template <class... Args>
DetachedThread(const Options & options,Args &&...args)35 void DetachedThread(const Options& options, Args&&... args) {
36 Thread(options, std::forward<Args>(args)...).detach();
37 }
38
39 } // namespace pw::thread
40