Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created March 31, 2022 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatilShreyas/5f9b8d0c9a1890bc52f82bd190e62b8f to your computer and use it in GitHub Desktop.
Save PatilShreyas/5f9b8d0c9a1890bc52f82bd190e62b8f to your computer and use it in GitHub Desktop.
// This is example to explain the API for semaphore
fun main() {
// Creates semaphore with 10 permits
val semaphore = Semaphore(permits = 10)
// Acquires a permit from this semaphore, suspending until one is available.
// All suspending acquirers are processed in first-in-first-out (FIFO) order
semaphore.acquire()
// Releases a permit, returning it into this semaphore.
// Resumes the first suspending acquirer if there is one at the point of invocation
semaphore.release()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment