Skip to content

TBB executor for GAPI: fix race consition in Async test#18982

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
anton-potapov:sole_tbb_executor_async_test
Dec 1, 2020
Merged

TBB executor for GAPI: fix race consition in Async test#18982
opencv-pushbot merged 1 commit intoopencv:masterfrom
anton-potapov:sole_tbb_executor_async_test

Conversation

@anton-potapov
Copy link
Copy Markdown
Contributor

@anton-potapov anton-potapov commented Dec 1, 2020

The test has race condition, which is addressed by the patch.

The race is next:

  1. Master thread is calling execute (effectively blocked, waiting for callback to be called)
  2. "Async" thread picks up the callback
  3. Call the callback
  4. Then sets the variables in test
  5. 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

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

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 opencv#18974
@asmorkalov
Copy link
Copy Markdown
Contributor

@anton-potapov The patch includes some fixes in Python code that are not relevant to your bug. Please rebase the patch ans fix conflicts.

@anton-potapov anton-potapov force-pushed the sole_tbb_executor_async_test branch from 1232a87 to eb6d8e6 Compare December 1, 2020 08:48
@anton-potapov
Copy link
Copy Markdown
Contributor Author

@anton-potapov The patch includes some fixes in Python code that are not relevant to your bug. Please rebase the patch ans fix conflicts.

updated

@anton-potapov anton-potapov added this to the 4.5.1 milestone Dec 1, 2020
@anton-potapov
Copy link
Copy Markdown
Contributor Author

@alalek please merge it

@opencv-pushbot opencv-pushbot merged commit 6f5af6e into opencv:master Dec 1, 2020
@alalek alalek mentioned this pull request Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

G-API: sporadic test failures TBBExecutor.AsyncBasic

5 participants