Taskflow  3.2.0-Master-Branch
Loading...
Searching...
No Matches
critical.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "../core/task.hpp"
4
10namespace tf {
11
12// ----------------------------------------------------------------------------
13// CriticalSection
14// ----------------------------------------------------------------------------
15
49class CriticalSection : public Semaphore {
50
51 public:
52
56 explicit CriticalSection(size_t max_workers = 1);
57
61 template <typename... Tasks>
62 void add(Tasks...tasks);
63};
64
65inline CriticalSection::CriticalSection(size_t max_workers) :
66 Semaphore {max_workers} {
67}
68
69template <typename... Tasks>
70void CriticalSection::add(Tasks... tasks) {
71 (tasks.acquire(*this), ...);
72 (tasks.release(*this), ...);
73}
74
75
76} // end of namespace tf. ---------------------------------------------------
77
78
class to create a critical region of limited workers to run tasks
Definition critical.hpp:49
void add(Tasks...tasks)
adds a task into the critical region
Definition critical.hpp:70
CriticalSection(size_t max_workers=1)
constructs a critical region of a limited number of workers
Definition critical.hpp:65
class to create a semophore object for building a concurrency constraint
Definition semaphore.hpp:68
taskflow namespace
Definition small_vector.hpp:27