Skip to content

cobusc/erlang_semaphore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

semaphore

Semaphore is an Erlang library providing functionality similar to that of POSIX semaphores.

Creating the semaphore

To create a semaphore named sem_name with a value of 2, use:

semaphore:start_link(sem_name, 2).

Semaphore functions

wait

This call blocks until the semaphore becomes available. It will always return ok and is equivalent to calling semaphore:timed_wait(sem_name, infinity).

Example:

semaphore:wait(sem_name).

try_wait

This is a non-blocking call to the semaphore. It will immediately return either ok if the semaphore was acquired, or error if not.

Eaxmple:

semaphore:try_wait(sem_name).

timed_wait

This call blocks until either the semaphore becomes available or the specified timeout (in milliseconds) is reached. It returns ok if the semaphore was acuired, or {error, timeout} if the timeout was reached.

semaphore:timed_wait(sem_name, 1000).

post

This call releases the semaphore. It returns ok if successful and error if the calling process did not acquire the semaphore.

semaphore:post(sem_name).

get_value

This call returns the current value of the semaphore.

semaphore:get_value(sem_name).

About

Semaphore functionality implemented using a gen_server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages