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