-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Atomic increment is now performed within one enqueued operation (#…
…330) * Version 1.5.10 * fix: Atomic increment is now performed within one enqueued operation --------- Co-authored-by: Brandon Sneed <[email protected]>
- Loading branch information
1 parent
a1b519e
commit 89014de
Showing
6 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import XCTest | ||
@testable import Segment | ||
|
||
final class Atomic_Tests: XCTestCase { | ||
|
||
func testAtomicIncrement() { | ||
|
||
@Atomic var counter = 0 | ||
|
||
DispatchQueue.concurrentPerform(iterations: 1000) { _ in | ||
// counter += 1 would fail, because it is expanded to: | ||
// `let oldValue = queue.sync { counter }` | ||
// `queue.sync { counter = oldValue + 1 }` | ||
// And the threads are free to suspend in between the two calls to `queue.sync`. | ||
|
||
_counter.withValue { value in | ||
value += 1 | ||
} | ||
} | ||
|
||
XCTAssertEqual(counter, 1000) | ||
} | ||
} |