Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concurrent_[bounded_]queue correctness on weak memory models #782

Merged
merged 6 commits into from
Nov 4, 2022

Conversation

alexey-katranov
Copy link
Contributor

Description

The patch fixes two issues:

  1. Memory corruption over micro_queue page allocation. tail_counter is serialization atomic that synchronizes memory related to micro_queue pages. Hence, we need to build happens-before over tail_counter (not to read it with relaxed)
  2. Enforce user expected happens-before relation for concurrent push and try_pop operations. Consider the example:
// thread 1
q.push()
q.try_pop()

// thread 2
q.push()
q.try_pop()

The expected global order of operation is either push->try_pop->push->try_pop or push->push->try_pop->try_pop. However, the current implementation allows push->try_pop->try_pop->push that is not intuitively expected by humans. So, set the constraint between head and tail loads to enforce visibility of push if try_pop is already happened.

The both issues are not reproducible on x86 and affect only systems with weak memory model, e.g. ARM.

  • - git commit message contains an appropriate signed-off-by string (see CONTRIBUTING.md for details)

Type of change

Choose one or multiple, leave empty if none of the other choices apply

Add a respective label(s) to PR if you have permissions

  • bug fix - change that fixes an issue
  • new feature - change that adds functionality
  • tests - change in tests
  • infrastructure - change in infrastructure and CI
  • documentation - documentation update

Tests

  • added - required for new features and some bug fixes
  • not needed

Documentation

  • updated in # - add PR number
  • needs to be updated
  • not needed

Breaks backward compatibility

  • Yes
  • No
  • Unknown

Notify the following users

Other information

Signed-off-by: Alexei Katranov <[email protected]>
include/oneapi/tbb/concurrent_queue.h Outdated Show resolved Hide resolved
include/oneapi/tbb/concurrent_queue.h Outdated Show resolved Hide resolved
Signed-off-by: pavelkumbrasev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants