File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,10 @@ class Latch {
40
40
41
41
public:
42
42
explicit Latch (uint32_t Count = 0 ) : Count(Count) {}
43
- ~Latch () { sync (); }
43
+ ~Latch () {
44
+ // Ensure at least that sync() was called.
45
+ assert (Count == 0 );
46
+ }
44
47
45
48
void inc () {
46
49
std::lock_guard<std::mutex> lock (Mutex);
Original file line number Diff line number Diff line change @@ -151,7 +151,12 @@ static std::atomic<int> TaskGroupInstances;
151
151
// lock, only allow the first TaskGroup to run tasks parallelly. In the scenario
152
152
// of nested parallel_for_each(), only the outermost one runs parallelly.
153
153
TaskGroup::TaskGroup () : Parallel(TaskGroupInstances++ == 0 ) {}
154
- TaskGroup::~TaskGroup () { --TaskGroupInstances; }
154
+ TaskGroup::~TaskGroup () {
155
+ // We must ensure that all the workloads have finished before decrementing the
156
+ // instances count.
157
+ L.sync ();
158
+ --TaskGroupInstances;
159
+ }
155
160
156
161
void TaskGroup::spawn (std::function<void ()> F) {
157
162
if (Parallel) {
You can’t perform that action at this time.
0 commit comments