Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. semaphore

semaphore

MITGov4.4.1

A Go library implementing the semaphore pattern with timeout support for lock/unlock operations.

GitHubGitHub
102 stars11 forks0 contributors

What is semaphore?

Semaphore is a Go library that implements the semaphore concurrency pattern to control access to shared resources or limit throughput across goroutines. It provides a clean API with timeout support for both acquiring and releasing locks, making it suitable for building scalable and resilient concurrent applications.

Target Audience

Go developers building concurrent applications that require precise control over resource access or request throttling, such as web servers or parallel task executors.

Value Proposition

Developers choose Semaphore for its idiomatic Go API, seamless integration with Go's context package for cancellation, and built-in timeout support to prevent deadlocks, offering a minimal and reliable solution for concurrency control.

Overview

🚦 Semaphore pattern implementation with timeout of lock/unlock operations.

Use Cases

Best For

  • Limiting simultaneous access to shared resources in concurrent Go applications.
  • Throttling request handling in web servers to prevent overload.
  • Executing multiple console commands in parallel with controlled concurrency using the included CLI tool.
  • Building resilient applications that require timeout and cancellation support for lock operations.
  • Integrating semaphore-based concurrency control with Go's native context package for deadline propagation.
  • Managing goroutine concurrency in scenarios where deadlock prevention is critical.

Not Ideal For

  • Projects requiring strict backward compatibility across major library updates
  • Simple concurrency tasks where Go's built-in sync primitives are sufficient
  • Teams that prefer lightweight solutions without external dependencies for basic throttling

Pros & Cons

Pros

Timeout and Context Support

Provides configurable timeouts for lock acquisition and release, and integrates seamlessly with Go's context package for cancellation, as shown in the HTTP handler example to prevent deadlocks.

Idiomatic Go API

Offers a minimal, clean API that aligns with Go's concurrency patterns, making it easy to adopt for developers familiar with the language's native primitives.

Built-in CLI Tool

Includes a command-line utility for executing multiple console commands in parallel with semaphore-based coordination, demonstrated in the semaphore create/add/wait example.

Semantic Versioning

Follows SemVer for versioning, ensuring predictable release cycles and stable updates, as mentioned in the integration section.

Cons

Breaking Major Releases

The library is not backward-compatible through major versions, which can cause migration headaches and code updates, as explicitly stated in the README.

External Dependency Integration

Version v5 is focused on integration with the breaker package, adding an external dependency that might not be necessary for all use cases, potentially increasing complexity.

Complex Versioning Setup

Multiple branches (master, v4, v5) with different installation commands, such as specific go get paths, can confuse users and complicate setup.

Frequently Asked Questions

Quick Stats

Stars102
Forks11
Contributors0
Open Issues6
Last commit2 days ago
CreatedSince 2016

Tags

#hacktoberfest#library#limiter#go-library#command-line-tool#timeout-handling#module#goroutines#golang#rate-limiting#concurrency#context-integration#go#semaphore#awesome-go

Built With

G
Go

Included in

Go169.1k
Auto-fetched 18 hours ago

Related Projects

antsants

🐜🐜🐜 ants is the most powerful and reliable pooling solution for Go.

Stars14,468
Forks1,437
Last commit20 days ago
concconc

Better structured concurrency for go

Stars10,417
Forks359
Last commit21 days ago
tunnytunny

A goroutine pool for Go

Stars4,033
Forks309
Last commit3 years ago
goworkergoworker

goworker is a Go-based background worker that runs 10 to 100,000* times faster than Ruby-based workers.

Stars2,847
Forks243
Last commit1 year ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub