IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

BlockingSpinLock

struct BlockingSpinLock

A basic locking implementation that uses an integer to represent the owner of the lock.

Fields

  • counter (Atomic[DType.int64]): The atomic counter implementing the spin lock.

Implemented traits

AnyType, Defaultable, ImplicitlyDestructible

comptime members

UNLOCKED

comptime UNLOCKED = -1

Non-zero means locked, -1 means unlocked.

Methods

__init__

__init__(out self)

Default constructor.

lock

lock(mut self, owner: Int)

Acquires the lock.

Args:

  • owner (Int): The lock's owner (usually an address).

unlock

unlock(mut self, owner: Int) -> Bool

Releases the lock.

Args:

  • owner (Int): The lock's owner (usually an address).

Returns:

Bool: The successful release of the lock.