RxSwift: RxAtomic causes Thread Sanitiser race conditions

Short description of the issue:

The newly added AtomicInt.swift causes data race reports from the Xcode Thread Sanitiser when running in DEBUG on iOS Simulator

Expected outcome:

No reports of data races.

What actually happens:

Any subroutines wrapped in TRACE_RESOURCES involved with incrementing or decrementing counters can trigger Thread Sanitiser data race reports.

Self contained code example that reproduces the issue:

  var atomicTester = AtomicInt(0)

        for i in 0...100 {
            DispatchQueue.global(qos: .background).async {
                if i % 2 == 0 {
                    self.atomicTester.increment()
                } else {
                    self.atomicTester.decrement()
                }
            }
        }  

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

4.4.0

Platform/Environment

  • [* ] iOS
  • [ *] macOS
  • [*] tvOS
  • [* ] watchOS
  • [* ] playgrounds

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

  • [* ] easy, 100% repro
  • sometimes, 10%-100%
  • hard, 2% - 10%
  • extremely hard, %0 - 2%

Xcode version:

10.1 (10B61)

⚠️ Fields below are optional for general issues or in case those questions aren’t related to your issue, but filling them out will increase the chances of getting your issue resolved. ⚠️

Installation method:

  • CocoaPods
  • Carthage
  • [*] Git submodules

I have multiple versions of Xcode installed: (so we can know if this is a potential cause of your issue)

  • yes (which ones)
  • [ *] no

Level of RxSwift knowledge: (this is so we can understand your level of knowledge and formulate the response in an appropriate manner)

  • just starting
  • I have a small code base
  • [* ] I have a significant code base

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 24 (21 by maintainers)

Most upvoted comments

The issue no longer occurs with pulls from the master branch and I have verified that RxSwift is very definitely making use of the restructured AtomicInt objects. Thanks so much, guys. I can’t wait for this to be included in a formal release.

@andyj-at-aspin I’ve merged fixes for TSan, please check the master branch. I would like to close this issue.

Thnx a lot @LucianoPAlmeida .

I had some free time so, did #1860 maybe it can be useful 😃)

I somehow doubt that we’ll come close to the speed of the current version of AtomicInt 😃