๐ Synchronization โ
The synchronization crate standardizes synchronization primitives used across Core.
Role โ
- Re-exports
embassy_syncprimitives through one crate-local entry point. - Provides portable
Arc/Weaksupport, including a custom fallback for targets without atomic pointer support.
Boundaries โ
- In scope: synchronization primitives and ownership wrappers.
- Out of scope: scheduler/executor implementation and task lifecycle policy.
Internal structure โ
lib.rs: top-level re-exports.arc/mod.rs: target-gated arc selection.- With
target_has_atomic = "ptr": usesalloc::sync::Arc/Weak. - Without pointer atomics: uses
arc/arc_lock.rsmutex-backed Arc implementation.
- With
Runtime interaction โ
- Modules and executables import mutex/rwlock/once/channel primitives from this crate.
- Fallback Arc implementation uses
CriticalSectionRawMutex+RefCellcounters for no-atomic targets.
Dependency model โ
- Primary dependency:
embassy-sync(std feature enabled on host targets). - Broadly consumed by file-system backends, graphics, and other concurrent modules.
Failure semantics โ
- Most primitives are infallible at API level; contention manifests as wait/lock behavior.
- Fallback Arc enforces overflow checks on reference counters and may panic on overflow.
Extension points โ
- Additional wrappers/adapters can be added to normalize synchronization semantics across targets.
- Arc fallback can evolve independently while preserving exported
Arc/Weakcontract.
Contract vs implementation โ
- Contract: one consistent synchronization import surface across platforms.
- Current implementation: direct
embassy_syncre-export plus conditional Arc fallback implementation.
Limitations and trade-offs โ
- Behavior still inherits cooperative runtime assumptions from executor usage patterns.
- Fallback Arc prioritizes portability over lock-free performance.