Skip to main content

Module execution_permit

Module execution_permit 

Source
Expand description

Per-thread execution permit, released when the thread blocks.

Sui runs transaction execution on a pool of blocking threads whose concurrency is capped by a semaphore permit. Execution may need to block waiting for a value that another execution must produce (e.g. an object version). If a blocked thread keeps holding its permit, and enough threads block this way, no permit is left for the execution that would unblock them - a deadlock.

To avoid this, the permit is installed on the thread with set_execution_permit, and the blocking sync primitives in this crate call release_execution_permit the first time they must actually block (after a non-blocking try_ check fails). The permit is intentionally not re-acquired afterwards: this may briefly exceed the configured concurrency, but the excess resolves itself as tasks complete.

The permit is stored type-erased (Box<dyn Send>) so this crate need not depend on the specific semaphore; releasing it simply drops the box.

Structs§

ExecutionPermitGuard
Guard returned by set_execution_permit. Releases the thread’s permit on drop if a blocking primitive has not already done so.

Functions§

release_execution_permit
Releases (drops) the current thread’s execution permit if one is installed. Idempotent, and a no-op when no permit is installed. Called by blocking primitives immediately before they park or spin.
set_execution_permit
Installs permit as the current thread’s execution permit. Panics if one is already installed (each blocking-pool task installs exactly one permit for the duration of its run).