VTK
9.2.6
Main Page
Related Pages
Topics
Namespaces
Classes
Files
File List
File Members
Common
Core
SMP
STDThread
vtkSMPThreadPool.h
Go to the documentation of this file.
1
/*=========================================================================
2
3
Program: Visualization Toolkit
4
Module: vtkSMPThreadPool.h
5
6
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
All rights reserved.
8
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10
This software is distributed WITHOUT ANY WARRANTY; without even
11
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
PURPOSE. See the above copyright notice for more information.
13
14
=========================================================================*/
15
// .NAME vtkSMPThreadPool - A thread pool implementation using std::thread
16
//
17
// .SECTION Description
18
// vtkSMPThreadPool class creates a thread pool of std::thread, the number
19
// of thread must be specified at the initialization of the class.
20
// The DoJob() method is used attributes the job to a free thread, if all
21
// threads are working, the job is kept in a queue. Note that vtkSMPThreadPool
22
// destructor joins threads and finish the jobs in the queue.
23
24
#ifndef vtkSMPThreadPool_h
25
#define vtkSMPThreadPool_h
26
27
#include "vtkCommonCoreModule.h"
// For export macro
28
#include "
vtkSystemIncludes.h
"
29
30
#include <condition_variable>
// For std::condition_variable
31
#include <functional>
// For std::function
32
#include <mutex>
// For std::mutex
33
#include <queue>
// For std::queue
34
#include <thread>
// For std::thread
35
36
namespace
vtk
37
{
38
namespace
detail
39
{
40
namespace
smp
41
{
42
43
class
VTKCOMMONCORE_EXPORT
vtkSMPThreadPool
44
{
45
public
:
46
explicit
vtkSMPThreadPool
(
int
ThreadNumber);
47
48
void
Join
();
49
void
DoJob
(std::function<
void
(
void
)> job);
50
51
private
:
52
void
ThreadJob();
53
54
private
:
55
std::mutex Mutex;
56
bool
Joining =
false
;
57
std::condition_variable ConditionVariable;
58
std::queue<std::function<void(
void
)>> JobQueue;
59
std::vector<std::thread> Threads;
60
};
61
62
}
// namespace smp
63
}
// namespace detail
64
}
// namespace vtk
65
66
#endif
vtk::detail::smp::vtkSMPThreadPool
Definition
vtkSMPThreadPool.h:44
vtk::detail::smp::vtkSMPThreadPool::Join
void Join()
vtk::detail::smp::vtkSMPThreadPool::DoJob
void DoJob(std::function< void(void)> job)
vtk::detail::smp::vtkSMPThreadPool::vtkSMPThreadPool
vtkSMPThreadPool(int ThreadNumber)
detail
Definition
vtkGenericDataArrayLookupHelper.h:33
vtk
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
Definition
vtkSMPThreadLocalAPI.h:42
vtkSystemIncludes.h
Generated on Sat Jul 20 2024 00:00:00 for VTK by
1.11.0