nareshmlx/opencv-pr huggingface dataset:
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,67 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "thread_pool.hpp"
+
```

Review comment:
Normally you don't need `start()` for a thread pool. You don't need stop either. How often this `start/stop()` will be called?
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,67 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "thread_pool.hpp"
+
```

Review comment:
why do you need `current` at all?
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,67 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "thread_pool.hpp"
+
```

Review comment:
so you increase you wait count once you schedule a task, and decrease once you're done with it -- why?
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 44

**Code Changes:**
```diff
+void cv::gapi::own::ThreadPool::worker(QueueClass<Task>& queue) {
+    while (true) {
+        cv::gapi::own::ThreadPool::Task task;
+        queue.pop(task);
+        if (!task) {
+            break;
+        }
+        task();
+    }
+}
+
```

Review comment:
Does this mean you terminate your worked threads once the graph is done?
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,67 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "thread_pool.hpp"
+
```

Review comment:
Shouldn't this be `&&task` ?
**File:** modules/gapi/CMakeLists.txt
**Change Type:** modified
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 128

**Code Changes:**
```diff
     src/executor/gexecutor.cpp
     src/executor/gtbbexecutor.cpp
+    src/executor/gthreadedexecutor.cpp
     src/executor/gstreamingexecutor.cpp
     src/executor/gasync.cpp
+    src/executor/thread_pool.cpp
 
     # CPU Backend (currently built-in)
     src/backends/cpu/gcpubackend.cpp
```

Review comment:
I guess you refer to `RequestPool`'s from `ie` and `ov` backends.
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,511 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "precomp.hpp"
+
```

Review comment:
It's just a copy-paste from `gexecutor.cpp` but no problem to address it :)
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,511 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "precomp.hpp"
+
```

Review comment:
Can we get a simultaneous read + write situation for the exception? Shouldn't it be protected (e.g. atomic)?
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,511 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "precomp.hpp"
+
```

Review comment:
Please, correct me, but how `deps` here are `producers`? IMHO they are still the same consumers of the current task
**File:** modules/gapi/src/executor/gthreadedexecutor.hpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,123 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#ifndef OPENCV_GAPI_GTHREADEDEXECUTOR_HPP
+#define OPENCV_GAPI_GTHREADEDEXECUTOR_HPP
```

Review comment:
Please, leave a comment in code
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,67 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "thread_pool.hpp"
+
```

Review comment:
Do we care if this line can be unreachable due to hang/exception in task above?
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,511 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "precomp.hpp"
+
```

Review comment:
Looks it's not `memory_order::seq_cst` for sure
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,67 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "thread_pool.hpp"
+
```

Review comment:
Quite handy though, user doesn't need to keep `ThreadPool` for scheduling `nested` tasks. ``` static void foo() { // do something ThreadPool::get()->schedule(bar); }; static void bar() { // do something ThreadPool::get()->schedule(baz); } ... ThreadPool tp; tp.schedule(foo); ``` But if we have plan to make `ThreadPool` available for all `GCompiled`'s, it can be removed for now
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,67 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "thread_pool.hpp"
+
```

Review comment:
The entire `WaitGroup` are used to implement `ThreadPool::wait()` that is supposed to block until all scheduled tasks, including nested ones, are completed
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 44

**Code Changes:**
```diff
+void cv::gapi::own::ThreadPool::worker(QueueClass<Task>& queue) {
+    while (true) {
+        cv::gapi::own::ThreadPool::Task task;
+        queue.pop(task);
+        if (!task) {
+            break;
+        }
+        task();
+    }
+}
+
```

Review comment:
The answer is NO, workers are terminated in the `ThreadPool::stop` that called during `GCompiled` destruction.
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,511 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "precomp.hpp"
+
```

Review comment:
`IslandActor` itself doesn't give any thread-safe guarantees, besides this method is called only in main thread when all tasks are completed.
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,67 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "thread_pool.hpp"
+
```

Review comment:
It's assumed that `task` can't throw exception at this point. Make sense to check it with something like this: `static_assert(noexcept(task()))` Since [this](https://en.cppreference.com/w/cpp/types/is_invocable) is available since C++17 only
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,511 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "precomp.hpp"
+
```

Review comment:
> Why are the inputs/outputs created right before run? I believe they could be created in the ctor and then reused across runs? They are lazy and their sense and only do the job when are called to? Mostly because they are defined in `*.cpp` file, we do the same for the regular `GExecutor`. Again, no problems, to address it in this PR :)
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,511 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "precomp.hpp"
+
```

Review comment:
Yes, you're right, this is the list of `consumers`
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,511 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "precomp.hpp"
+
```

Review comment:
From my point of view, the `dependencies` is better name since it describes relationship between tasks. The one task may depend on several other tasks but task itself doesn't consume or produce other tasks.
**File:** modules/gapi/src/executor/thread_pool.hpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,71 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+#ifndef OPENCV_GAPI_THREAD_POOL_HPP
+#define OPENCV_GAPI_THREAD_POOL_HPP
+
```

Review comment:
No, the difference there is that `WaitGroup` is working with arbitrary number of `tasks` that can be added dynamically while the `Barrier` knows upfront how many tasks it waits.
**File:** modules/gapi/src/executor/thread_pool.hpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,71 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+#ifndef OPENCV_GAPI_THREAD_POOL_HPP
+#define OPENCV_GAPI_THREAD_POOL_HPP
+
```

Review comment:
As we discussed, we know our graph structure before hand, so we know upfront how many tasks we should wait The suggestion is to remove `wait()` and wait for the completion outside the `ThreadPool` (e.g by using something like barrier)
**File:** modules/gapi/include/opencv2/gapi/gcommon.hpp
**Change Type:** modified
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -263,12 +263,32 @@ struct graph_dump_path
 };
 /** @} */
 
+/**
+ * @brief Ask G-API to use threaded executor when cv::GComputation
+ * is compiled via cv::GComputation::compile method.
+ *
+ * Specifies a number of threads that should be used by executor.
+ */
```

Review comment:
Good point, I think we can use `cv::getNumThreads()` there instead. Done
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 231

**Code Changes:**
```diff
+      m_outputs(state, out_objects) {
+}
+
+void cv::gimpl::IslandActor::run() {
+    m_isl_exec->run(m_inputs, m_outputs);
+}
+
+void cv::gimpl::IslandActor::verify() {
+    m_outputs.verify();
+};
+
```

Review comment:
If `GThreadedExecutor::Output` is the field of `IslandActor` and don't need this as `m_isl_exec->run()` not suppose to throw any exception. Will fix
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,67 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "thread_pool.hpp"
+
```

Review comment:
WaitGroup has been removed
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 44

**Code Changes:**
```diff
+void cv::gapi::own::ThreadPool::worker(QueueClass<Task>& queue) {
+    while (true) {
+        cv::gapi::own::ThreadPool::Task task;
+        queue.pop(task);
+        if (!task) {
+            break;
+        }
+        task();
+    }
+}
+
```

Review comment:
Not it's done in `shutdown` method which is private and called only in `~ThreadPool()`
**File:** modules/gapi/src/executor/thread_pool.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,67 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "thread_pool.hpp"
+
```

Review comment:
not relevant, WaitGroup has been removed
**File:** modules/gapi/include/opencv2/gapi/gcommon.hpp
**Change Type:** modified
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -263,12 +263,32 @@ struct graph_dump_path
 };
 /** @} */
 
+/**
+ * @brief Ask G-API to use threaded executor when cv::GComputation
+ * is compiled via cv::GComputation::compile method.
+ *
+ * Specifies a number of threads that should be used by executor.
+ */
```

Review comment:
Not needed any more
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 97

**Code Changes:**
```diff
+    case GRunArgP::index_of<cv::RMat*>() : /* do nothing */ break;
+    default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?"));
+    }
+}
+
+void assignMetaStubExec(Mag& mag, const RcDesc &rc, const cv::GRunArg::Meta &meta) {
+    switch (rc.shape) {
+    case GShape::GARRAY:  mag.meta<cv::detail::VectorRef>()[rc.id] = meta; break;
+    case GShape::GOPAQUE: mag.meta<cv::detail::OpaqueRef>()[rc.id] = meta; break;
+    case GShape::GSCALAR: mag.meta<cv::Scalar>()[rc.id]            = meta; break;
+    case GShape::GFRAME:  mag.meta<cv::MediaFrame>()[rc.id]        = meta; break;
```

Review comment:
Left mutex so far
**File:** modules/gapi/include/opencv2/gapi/gcommon.hpp
**Change Type:** modified
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -263,12 +263,32 @@ struct graph_dump_path
 };
 /** @} */
 
+/**
+ * @brief Ask G-API to use threaded executor when cv::GComputation
+ * is compiled via cv::GComputation::compile method.
+ *
+ * Specifies a number of threads that should be used by executor.
+ */
```

Review comment:
probably it's not ok to have `cv::getNumThreads()` called in the header. Instead, you could introduce two constructors, a default one `()` with `nthreads` set to `cv::getNumThreads()` in its initializer list, and the value-based one.
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,511 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "precomp.hpp"
+
```

Review comment:
A strange mix of `{`, can you please stick to the BSD-style one?
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -0,0 +1,511 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+//
+// Copyright (C) 2024 Intel Corporation
+
+
+#include "precomp.hpp"
+
```

Review comment:
this is the third indentation style I see in this file
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 245

**Code Changes:**
```diff
+    using Ptr = std::shared_ptr<Task>;
+    Task(TaskManager::F&& f, std::vector<Task::Ptr> &&producers);
+
+    struct ExecutionState {
+        cv::gapi::own::ThreadPool& tp;
+        cv::gapi::own::Latch& latch;
+    };
+
+    void run(ExecutionState& state);
+    bool isLast() const { return m_consumers.empty();  }
+    void reset()        { m_ready_producers.store(0u); }
```

Review comment:
latch? what's this?:)
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 274

**Code Changes:**
```diff
+    // Execute the task
+    m_f();
+    // Notify every consumer about completion one of its dependencies
+    for (auto* consumer : m_consumers) {
+        const auto num_ready =
+            consumer->m_ready_producers.fetch_add(1, std::memory_order_relaxed) + 1;
+        // The last completed producer schedule the consumer for execution
+        if (num_ready == consumer->m_num_producers) {
+            state.tp.schedule([&state, consumer](){
+                consumer->run(state);
+            });
```

Review comment:
Why don't u use pre-increment here, again?
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 245

**Code Changes:**
```diff
+    using Ptr = std::shared_ptr<Task>;
+    Task(TaskManager::F&& f, std::vector<Task::Ptr> &&producers);
+
+    struct ExecutionState {
+        cv::gapi::own::ThreadPool& tp;
+        cv::gapi::own::Latch& latch;
+    };
+
+    void run(ExecutionState& state);
+    bool isLast() const { return m_consumers.empty();  }
+    void reset()        { m_ready_producers.store(0u); }
```

Review comment:
I believe it's https://en.cppreference.com/w/cpp/thread/latch
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 274

**Code Changes:**
```diff
+    // Execute the task
+    m_f();
+    // Notify every consumer about completion one of its dependencies
+    for (auto* consumer : m_consumers) {
+        const auto num_ready =
+            consumer->m_ready_producers.fetch_add(1, std::memory_order_relaxed) + 1;
+        // The last completed producer schedule the consumer for execution
+        if (num_ready == consumer->m_num_producers) {
+            state.tp.schedule([&state, consumer](){
+                consumer->run(state);
+            });
```

Review comment:
only because I specify `memory_order` there
**File:** modules/gapi/include/opencv2/gapi/gcommon.hpp
**Change Type:** modified
**Context:** PR #24845: G-API: Implement concurrent executor

**Code Changes:**
```diff
@@ -263,12 +263,32 @@ struct graph_dump_path
 };
 /** @} */
 
+/**
+ * @brief Ask G-API to use threaded executor when cv::GComputation
+ * is compiled via cv::GComputation::compile method.
+ *
+ * Specifies a number of threads that should be used by executor.
+ */
```

Review comment:
Can't we just declare it here and move implementation to a cpp file?
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 245

**Code Changes:**
```diff
+    using Ptr = std::shared_ptr<Task>;
+    Task(TaskManager::F&& f, std::vector<Task::Ptr> &&producers);
+
+    struct ExecutionState {
+        cv::gapi::own::ThreadPool& tp;
+        cv::gapi::own::Latch& latch;
+    };
+
+    void run(ExecutionState& state);
+    bool isLast() const { return m_consumers.empty();  }
+    void reset()        { m_ready_producers.store(0u); }
```

Review comment:
well, it's just single use barrier, naming suggestions are welcome
**File:** modules/gapi/src/executor/gthreadedexecutor.cpp
**Change Type:** added
**Context:** PR #24845: G-API: Implement concurrent executor
**Review Line:** 309

**Code Changes:**
```diff
+    // Reset the number of ready dependencies for all tasks
+    for (auto& task : m_all_tasks) { task->reset(); }
+
+    // Count the number of last tasks
+    auto isLast = [](const std::shared_ptr<Task>& task) { return task->isLast(); };
+    const auto kNumLastsTasks =
+        std::count_if(m_all_tasks.begin(), m_all_tasks.end(), isLast);
+
+    // Initialize the latch, schedule initial tasks
+    // and wait until all lasts tasks are done
+    cv::gapi::own::Latch latch(kNumLastsTasks);
```

Review comment:
Does it handle recursive task creation?