From eb6d8e6af233e0c021bfae4e04f36b2b844157a8 Mon Sep 17 00:00:00 2001 From: Anton Potapov Date: Tue, 1 Dec 2020 11:12:36 +0300 Subject: [PATCH] TBB executor for GAPI: fix race consition in Async test The test has race condition, which is addressed by the patch. The race is next: Master thread is calling execute (effectively blocked, waiting for callback to be called) "Async" thread picks up the callback Call the callback Then sets the variables in test After call back is called, master thread is unblocked and may check the variables (set in point 4 by the "async" thread) earlier then they actually changed Changes: callback should be called as the last step (after flag variables are set), as it effectively unblock the master thread fixes #18974 --- modules/gapi/test/executor/gtbbexecutor_internal_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gapi/test/executor/gtbbexecutor_internal_tests.cpp b/modules/gapi/test/executor/gtbbexecutor_internal_tests.cpp index d793683f94..bdc3bb2360 100644 --- a/modules/gapi/test/executor/gtbbexecutor_internal_tests.cpp +++ b/modules/gapi/test/executor/gtbbexecutor_internal_tests.cpp @@ -95,9 +95,9 @@ TEST(TBBExecutor, AsyncBasic) { if (!slept) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } - callback(); callback_called = true; master_was_blocked_until_callback_called = (master_is_waiting == true); + callback(); }); auto async_task_body = [&](std::function&& cb, size_t /*total_order_index*/) {