oneTBB icon indicating copy to clipboard operation
oneTBB copied to clipboard

Fix concurrent_[bounded_]queue correctness on weak memory models

Open alexey-katranov opened this issue 3 years ago • 0 comments

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.

  • [x] - 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

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

Tests

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

Documentation

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

Breaks backward compatibility

  • [ ] Yes
  • [x] No
  • [ ] Unknown

Notify the following users

Other information

alexey-katranov avatar Feb 21 '22 12:02 alexey-katranov