native_synchronization
0.3.1, released 2 years ago by labs.dart.dev
Provides low‑level thread synchronization primitives (Mutex, ConditionVariable, Mailbox) via dart:ffi.
What it does
The package exposes portable interfaces for native synchronization primitives such as Mutex and ConditionVariable. It also offers higher‑level constructs like Mailbox built on top of those primitives. All implementations rely on dart:ffi to call platform‑specific APIs.
AI-written summary of version 0.3.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need fine‑grained thread coordination across isolates on native platforms
- You require a Mutex or ConditionVariable for shared‑memory synchronization in performance‑critical code
Skip it when
- Running on the web or other non‑FFI platforms
- You prefer higher‑level async abstractions like Future/Stream instead of manual locking
- You need a stable API; this package is marked experimental
Strengths
- Very low‑level, minimal overhead via native calls
- Works on all major desktop and mobile platforms (android, ios, windows, macos, linux)
- Provides both primitive and slightly higher‑level sync constructs
Weaknesses
- Experimental status means frequent breaking changes
- Only works where dart:ffi is available (no web support)
- Requires native build setup and understanding of synchronization concepts
Setup
- Kind
- FFI (native library)
- Effort
- Medium
- Code generation
- No
- Direct dependencies
- 1
Add the ffi dependency (already declared) and ensure your project is configured to build native code for the target platforms. No additional permissions are required, but you must compile for a platform that supports dart:ffi.
import 'package:native_synchronization/native_synchronization.dart';
void main() {
final mutex = Mutex();
mutex.lock();
// critical section
print('locked');
mutex.unlock();
}Alternatives
Packages that do the same job and could replace native_synchronization.
- async_locks
Synchronization primitives for asynchronous Dart code like Lock, Event, and Semaphore
53Compare - linkify
Low-level Dart library that parses text into URLs, emails, phone numbers and user tags.
50Compare - jsontool
Low‑level tools for reading and writing JSON without creating intermediate Dart objects
50Compare - flutter_olm
Builds the native Olm library for Android and iOS to be used via dart:ffi.
40Compare
Works with
Packages commonly used together with native_synchronization: ones it builds on, ones built on it, and its own family.
- ffinative_synchronization depends on itUtilities for working with Foreign Function Interface (FFI) code in Dart.
- native_toolchain_cSame familyInvoke the native C compiler installed on the host machine.
- sassBuilt on native_synchronizationA Dart implementation of Sass for compiling Sass and SCSS to CSS.