Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TTaskGroup.hxx
Go to the documentation of this file.
1 // @(#)root/thread:$Id$
2 // Author: Danilo Piparo August 2017
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TTaskGroup
13 #define ROOT_TTaskGroup
14 
15 #include <atomic>
16 #include <functional>
17 
18 namespace ROOT {
19 namespace Experimental {
20 
21 class TTaskGroup {
22  /**
23  \class ROOT::Experimental::TTaskGroup
24  \ingroup Parallelism
25  \brief A class to manage the asynchronous execution of work items.
26 
27  A TTaskGroup represents concurrent execution of a group of tasks. Tasks may be dynamically added to the group as it
28  is executing.
29  */
30 private:
31  void *fTaskContainer{nullptr};
32  std::atomic<bool> fCanRun{true};
33  void ExecuteInIsolation(const std::function<void(void)> &operation);
34 
35 public:
36  TTaskGroup();
37  TTaskGroup(TTaskGroup &&other);
38  TTaskGroup(const TTaskGroup &) = delete;
39  TTaskGroup &operator=(TTaskGroup &&other);
40  ~TTaskGroup();
41 
42  void Cancel();
43  void Run(const std::function<void(void)> &closure);
44  void Wait();
45 };
46 } // namespace Experimental
47 } // namespace ROOT
48 
49 #endif