SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parallel4.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 Parallel4.h
33 ///@brief Automatically instantiate several threads, with 4 arguments
34 ///
35 ///@author Steve Parker
36 /// Department of Computer Science
37 /// University of Utah
38 ///@date June 1997
39 ///
40 
41 #ifndef Core_Thread_Parallel4_h
42 #define Core_Thread_Parallel4_h
43 
46 
47 namespace SCIRun {
48 /**************************************
49 
50 @class
51  Parallel4
52 
53  KEYWORDS
54  Thread
55 
56 @details
57  Helper class to make instantiating threads to perform a parallel
58  task easier.
59 
60 ****************************************/
61 template<class T, class Arg1, class Arg2, class Arg3, class Arg4> class Parallel4 :
62  public ParallelBase
63 {
64 public:
65  //////////
66  /// Create a Parallel4 object, using the specified member
67  /// function instead of <i>Parallel4</i>. This will
68  /// typically be used like:
69  /// <b><pre>Thread::Parallel4(Parallel4&lt;MyClass&gt;(this, &amp;MyClass::mymemberfn), nthreads);</pre></b>
70  Parallel4(T* obj,
71  void (T::*pmf)(int, Arg1, Arg2, Arg3, Arg4),
72  Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4);
73 
74  //////////
75  /// Destroy the Parallel4 object - the threads will remain alive.
76  virtual ~Parallel4();
77  T* obj_;
78  void (T::*pmf_)(int, Arg1, Arg2, Arg3, Arg4);
79  Arg1 a1;
80  Arg2 a2;
81  Arg3 a3;
82  Arg4 a4;
83 protected:
84  virtual void run(int proc);
85 private:
86  // Cannot copy them
87  Parallel4(const Parallel4&);
89 };
90 
91 template<class T, class Arg1, class Arg2, class Arg3, class Arg4>
92 void
94 {
95  // Copy out do make sure that the call is atomic
96  T* obj=obj_;
97  void (T::*pmf)(int, Arg1, Arg2, Arg3, Arg4) = pmf_;
98  if(wait_)
99  wait_->up();
100  (obj->*pmf)(proc, a1, a2, a3, a4);
101  // Cannot do anything here, since the object may be deleted by the
102  // time we return
103 }
104 
105 template<class T, class Arg1, class Arg2, class Arg3, class Arg4>
107  void (T::*pmf)(int, Arg1, Arg2, Arg3, Arg4),
108  Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) :
109  obj_(obj),
110  pmf_(pmf),
111  a1(a1),
112  a2(a2),
113  a3(a3),
114  a4(a4)
115 {
116  wait_=0; // This may be set by Thread::parallel
117 } // End namespace SCIRun
118 
119 template<class T, class Arg1, class Arg2, class Arg3, class Arg4>
121 {
122 }
123 
124 } //End namespace SCIRun
125 
126 #endif
127 
128 
Arg3 a3
Definition: Parallel4.h:81
void(T::* pmf_)(int, Arg1, Arg2, Arg3, Arg4)
Definition: Parallel4.h:78
Parallel4(T *obj, void(T::*pmf)(int, Arg1, Arg2, Arg3, Arg4), Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4)
Definition: Parallel4.h:106
Definition: ParallelBase.h:62
Helper class to instantiate several threads.
Arg2 a2
Definition: Parallel4.h:80
T * obj_
Definition: Parallel4.h:77
Definition: Parallel4.h:61
Arg4 a4
Definition: Parallel4.h:82
virtual ~Parallel4()
Destroy the Parallel4 object - the threads will remain alive.
Definition: Parallel4.h:120
Arg1 a1
Definition: Parallel4.h:79
virtual void run(int proc)
The thread body
Definition: Parallel4.h:93
Semaphore * wait_
Definition: ParallelBase.h:71