oneTBB
oneTBB copied to clipboard
Fix concurrent_[bounded_]queue correctness on weak memory models
Description
The patch fixes two issues:
- 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 overtail_counter
(not to read it withrelaxed
) - Enforce user expected happens-before relation for concurrent
push
andtry_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