Skip to content

A fork of golang/x/sync/semaphore that is also resizable in runtime.

License

Notifications You must be signed in to change notification settings

sherifabdlnaby/semaphore

Repository files navigation

Semaphore

Build Status codecov License

A fork of golang/x/sync/semaphore that is also resizable.


This fork adds the ability to resize the semaphore in a concurrent-safe way.

  • Use semaphore.Resize(N) to resize the semaphore to a new absolute value N
  • Example

    sem := semaphore.NewWeighted(5)     // Semaphore size = 5
    result1 := sem.TryAcquire(10)       // returns false.
    sem.Resize(15)                      // Semaphore size now = 10
    result2 := sem.TryAcquire(10)       // returns true.
    fmt.Println(result1,result2)        // prints false \n true  
  • Added resize functionality has no impact on the semaphore performance according to benchmarks.
  • Tests for the newly added Resize() was also added.

About

A fork of golang/x/sync/semaphore that is also resizable in runtime.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages