SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ThreadGroup.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 ///
32 ///@file ThreadGroup.h
33 ///@brief A set of threads
34 ///
35 ///@author Steve Parker
36 /// Department of Computer Science
37 /// University of Utah
38 ///@date June 1997
39 ///
40 
41 #ifndef Core_Thread_ThreadGroup_h
42 #define Core_Thread_ThreadGroup_h
43 
45 
46 #include <vector>
47 
49 
50 namespace SCIRun {
51 
52 class Thread;
53 
54 /**************************************
55 
56 @class
57  ThreadGroup
58 
59 KEYWORDS
60  Thread
61 
62 @details
63  A group of threads that are linked together for scheduling
64  and control purposes. The threads may be stopped, resumed
65  and alerted simultaneously.
66 
67 ****************************************/
69  public:
70 
71  //////////
72  /// Create a thread group with the specified <i>name</i>.
73  /// <i>parentGroup</i> specifies the parent <b>ThreadGroup</b>
74  /// which defaults to the default top-level group.
75  ThreadGroup(const char* name, ThreadGroup* parentGroup=0);
76 
77  //////////
78  /// Destroy the thread group. All of the running threads
79  /// should be stopped before the <b>ThreadGroup</b> is destroyed.
80  ~ThreadGroup();
81 
82  //////////
83  /// Return a snapshot of the number of living threads. If
84  /// <i>countDaemon</i> is true, then daemon threads will be
85  /// included in the count.
86  int numActive(bool countDaemon);
87 
88  //////////
89  /// Stop all of the threads in this thread group
90  void stop();
91 
92  //////////
93  /// Resume all of the threads in this thread group
94  void resume();
95 
96  //////////
97  /// Wait until all of the threads have completed.
98  void join();
99 
100  //////////
101  /// Detach the thread, joins are no longer possible.
102  void detach();
103 
104  //////////
105  /// Return the parent <b>ThreadGroup.</b> Returns null if
106  /// this is the default threadgroup.
107  ThreadGroup* parentGroup();
108 
109  //////////
110  /// Arrange to have the threadGroup gang scheduled, so that
111  /// all of the threads will be executing at the same time if
112  /// multiprocessing resources permit. This interface will
113  /// typically be employed by the <i>Thread::parallel</i>
114  /// static method, and will typically not be called directly
115  /// by user code. Threads added to the group after this call
116  /// may or may not be included in the schedule gang.
117  void gangSchedule();
118 
119  protected:
120  friend class Thread;
122 
123  private:
124  Mutex lock_;
125  const char* name_;
126  ThreadGroup* parent_;
127  std::vector<ThreadGroup*> groups_;
128  std::vector<Thread*> threads_;
129  void addme(ThreadGroup* t);
130  void addme(Thread* t);
131 
132  // Cannot copy them
133  ThreadGroup(const ThreadGroup&);
134  ThreadGroup& operator=(const ThreadGroup&);
135  };
136 } // End namespace SCIRun
137 
138 #endif
139 
140 
Definition: Thread.h:67
#define SCISHARE
Definition: share.h:39
Definition: Mutex.h:65
const char * name[]
Definition: BoostGraphExampleTests.cc:87
static ThreadGroup * s_default_group
Definition: ThreadGroup.h:121
Definition: ThreadGroup.h:68