Repository navigation
Replace DispatchQueue-backed locks with Mutex - #89
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## claude/2.0-3-raise-minimums #89 +/- ##
=============================================================
Coverage 100.00% 100.00%
=============================================================
Files 12 12
Lines 1509 1476 -33
=============================================================
- Hits 1509 1476 -33
🚀 New features to boost your workflow:
|
dfed
force-pushed
the
claude/2.0-4-mutex
branch
from
November 15, 2026 15:45
f8572b3 to
ee9ebb7
Compare
Owner
Author
|
Correction: the CodeQL Swift failure I reported here is fixed by Generated by Claude Code |
Now that the platform minimums include the Synchronization module, use `Mutex` for the state that `Delivery` and `CancellableQueue` guard instead of hand-rolled locks built on serial dispatch queues. `CancellableQueue` also stops deferring its bookkeeping with `DispatchQueue.async`: reservations, registrations, and removals now apply synchronously, in program order. This is safe because no task is cancelled while the lock is held. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
dfed
force-pushed
the
claude/2.0-4-mutex
branch
from
November 16, 2026 23:40
ee9ebb7 to
0958fc0
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Now that the platform minimums include the Synchronization module,
DeliveryandCancellableQueueguard their state withMutexinstead of hand-rolled locks built on serial dispatch queues.CancellableQueuealso stops deferring its bookkeeping withDispatchQueue.async. Reservations, registrations, and removals now apply synchronously, in program order. That is safe because nothing is cancelled while the lock is held (#86 and #87).Tests
No test is added. Because registration is now synchronous:
cancelTasks_*_doesNotCancelFutureTaskstests drop the secondcancelTasks()call that Cancel tasks outside of CancellableQueue's lock #87 used to flush pending registrations, and check the task right after it ends;cancelTasks_*_cancelsCurrentlyExecutingThrowingTask*tests now say that the task registers its cancellation beforeTask(on:)returns.Series
PR 5 of 10. It is stacked on #88.
Validation
Each commit in the series was validated on its own, on Linux with Swift 6.4.2, from a
git archivecopy:-warnings-as-errors, andswiftformat --lintis clean.ci.ymlunderbash -e, pass, including the atomic-counter check. No line inSourcesorTestsreads zero in the CI run.Synchronization.Mutexeven in trivially correct code, so the TSan runs replaceMutexwith a pthread-based lock that TSan understands.Nothing was run on Apple platforms. CI is the first run there.
Review checklist
Left for code review because no test can force them:
Mutex,Delivery.cancel()must setisCancelledand read the task in onewithLock, andexecutemust store the task and readisCancelledin one. InCancellableQueue,cancelTasks()must collect its closures, and each reservation, registration and removal must update the map, in onewithLockeach. No test can force a thread switch inside one.Mutexis not reentrant, so cancelling underCancellableQueue's lock again would now deadlock: Cancel tasks outside of CancellableQueue's lock #87'scanBeCalledFromCancellationHandlertests would hang until the job's timeout.🤖 Generated with Claude Code
https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM