MCPcopy Create free account
hub / github.com/Kitware/VTK / SingleMethodExecute

Method SingleMethodExecute

Common/Core/vtkMultiThreader.cxx:188–309  ·  view source on GitHub ↗

Execute the method set as the SingleMethod on NumberOfThreads threads.

Source from the content-addressed store, hash-verified

186
187// Execute the method set as the SingleMethod on NumberOfThreads threads.
188void vtkMultiThreader::SingleMethodExecute()
189{
190 int thread_loop = 0;
191
192#ifdef VTK_USE_WIN32_THREADS
193 DWORD threadId;
194 HANDLE process_id[VTK_MAX_THREADS] = {};
195#endif
196
197#ifdef VTK_USE_PTHREADS
198 pthread_t process_id[VTK_MAX_THREADS] = {};
199#endif
200
201 if (!this->SingleMethod)
202 {
203 vtkErrorMacro(<< "No single method set!");
204 return;
205 }
206
207 // obey the global maximum number of threads limit
208 if (vtkMultiThreaderGlobalMaximumNumberOfThreads &&
209 this->NumberOfThreads > vtkMultiThreaderGlobalMaximumNumberOfThreads)
210 {
211 this->NumberOfThreads = vtkMultiThreaderGlobalMaximumNumberOfThreads;
212 }
213
214#ifdef VTK_USE_WIN32_THREADS
215 // Using CreateThread on Windows
216 //
217 // We want to use CreateThread to start this->NumberOfThreads - 1
218 // additional threads which will be used to call this->SingleMethod().
219 // The parent thread will also call this routine. When it is done,
220 // it will wait for all the children to finish.
221 //
222 // First, start up the this->NumberOfThreads-1 processes. Keep track
223 // of their process ids for use later in the waitid call
224 for (thread_loop = 1; thread_loop < this->NumberOfThreads; thread_loop++)
225 {
226 this->ThreadInfoArray[thread_loop].UserData = this->SingleData;
227 this->ThreadInfoArray[thread_loop].NumberOfThreads = this->NumberOfThreads;
228 process_id[thread_loop] = CreateThread(
229 nullptr, 0, this->SingleMethod, ((void*)(&this->ThreadInfoArray[thread_loop])), 0, &threadId);
230 if (process_id[thread_loop] == nullptr)
231 {
232 vtkErrorMacro("Error in thread creation !!!");
233 }
234 }
235
236 // Now, the parent thread calls this->SingleMethod() itself
237 this->ThreadInfoArray[0].UserData = this->SingleData;
238 this->ThreadInfoArray[0].NumberOfThreads = this->NumberOfThreads;
239 this->SingleMethod((void*)(&this->ThreadInfoArray[0]));
240
241 // The parent thread has finished this->SingleMethod() - so now it
242 // waits for each of the other processes to exit
243 for (thread_loop = 1; thread_loop < this->NumberOfThreads; thread_loop++)
244 {
245 WaitForSingleObject(process_id[thread_loop], INFINITE);

Callers 15

PLSDynaReaderFunction · 0.45
PSLACReaderLinearFunction · 0.45
PSLACReaderQuadraticFunction · 0.45
TestXdmf3ParallelFunction · 0.45
ParallelIso2Function · 0.45
ParallelIsoFunction · 0.45
ClearCPUCacheFunction · 0.45

Calls

no outgoing calls

Tested by 15

TestXdmf3ParallelFunction · 0.36
TestAtomicFunction · 0.36
TestLookupTableThreadedFunction · 0.36
TestSMPFeaturesFunction · 0.36
UpdateNormalsMethod · 0.36
TestParallelRenderingFunction · 0.36