Switon's synchronization primitives for bounded handoff, mutual exclusion, task joining, and LIFO reuse in coroutine and non-coroutine runtimes.
- Coroutine-friendly primitives: the same contracts work in coroutine and non-coroutine runtimes.
- Bounded channels:
Channelprovides fixed-capacity FIFO handoff. - Scoped mutexes:
Mutex::guard()returns a lock for deterministic release. - Task joining:
WaitGroupblocks until registered work finishes. - LIFO reuse:
Stackprovides fixed-capacity last-in-first-out reuse.
composer require switon/syncuse Switon\Sync\Channel;
use Switon\Sync\Mutex;
use Switon\Sync\WaitGroup;
$channel = new Channel(2);
$channel->push('task-1');
$task = $channel->pop();
$mutex = new Mutex();
$lock = $mutex->guard();
try {
// critical section
} finally {
$lock->release();
}
$wg = WaitGroup::of(2);
$wg->done();
$wg->done();
$wg->wait();Docs: https://docs.switon.dev/latest/sync
MIT.