Semaphore (semaphore v1.2.0)

Link to this section Summary

Functions

Acquire a semaphore, incrementing the internal count by one.

Acquire a semaphore, incrementing the internal count by one.

Attempt to acquire a semaphore and call a function and then automatically release.

Attempt to acquire a semaphore and call a function that might link to another process, and then automatically release.

Returns a specification to start this module under a supervisor.

Number of acquired semaphores.

Callback implementation for GenServer.init/1.

Release a semaphore, decrementing the internal count by one.

Release a semaphore, decrementing the internal count by one.

Reset sempahore to a specific count.

Link to this section Functions

Link to this function

acquire(name, max)

@spec acquire(term(), integer()) :: boolean()

Acquire a semaphore, incrementing the internal count by one.

Link to this function

acquire_linksafe(name, id, max)

@spec acquire_linksafe(term(), any(), integer()) :: boolean()

Acquire a semaphore, incrementing the internal count by one.

If the current process exits without releasing the semaphore, it will be automatically swept in the background. Like call_linksafe, tThis function has higher overhead than acquire/2.

Link to this function

call(name, max, func)

@spec call(term(), integer(), function()) :: term() | {:error, :max}

Attempt to acquire a semaphore and call a function and then automatically release.

Link to this function

call_linksafe(name, max, func)

@spec call_linksafe(term(), integer(), function()) :: term() | {:error, :max}

Attempt to acquire a semaphore and call a function that might link to another process, and then automatically release.

If the current process dies in a way that is unable to be caught by the try block (e.g. a linked process dies, while func is being called. The semaphore will be automatically released by the sweeper in the background.

This function has higher overhead than call/3 and should only be used if you know that you might be linking to something in the func.

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec count(term()) :: integer()

Number of acquired semaphores.

Link to this function

init(sweep_interval)

Callback implementation for GenServer.init/1.

@spec release(term()) :: :ok

Release a semaphore, decrementing the internal count by one.

Link to this function

release_linksafe(name, id)

@spec release_linksafe(term(), any()) :: :ok

Release a semaphore, decrementing the internal count by one.

If the current process exits without releasing the semaphore, it will be automatically swept in the background. Like call_linksafe, tThis function has higher overhead than acquire/2.

Link to this function

reset(name, count \\ 0)

@spec reset(term(), integer()) :: :ok

Reset sempahore to a specific count.

Link to this function

start(type, args)