{"id":13413105,"url":"https://github.com/marusama/semaphore","last_synced_at":"2026-01-11T21:56:38.336Z","repository":{"id":45290145,"uuid":"111691308","full_name":"marusama/semaphore","owner":"marusama","description":"Fast resizable golang semaphore primitive","archived":false,"fork":false,"pushed_at":"2021-03-28T09:27:47.000Z","size":78,"stargazers_count":177,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-13T17:38:29.573Z","etag":null,"topics":["go","golang","mutex","primitive","semaphore","semaphore-pattern","synchronization"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marusama.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-22T14:00:58.000Z","updated_at":"2025-07-22T10:01:33.000Z","dependencies_parsed_at":"2022-07-13T15:31:02.087Z","dependency_job_id":null,"html_url":"https://github.com/marusama/semaphore","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/marusama/semaphore","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marusama%2Fsemaphore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marusama%2Fsemaphore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marusama%2Fsemaphore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marusama%2Fsemaphore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marusama","download_url":"https://codeload.github.com/marusama/semaphore/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marusama%2Fsemaphore/sbom","scorecard":{"id":622237,"data":{"date":"2025-08-11","repo":{"name":"github.com/marusama/semaphore","commit":"2d3c1eaa054b6e36c7c0dfde398f2b47e4bc5094"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Code-Review","score":1,"reason":"Found 3/27 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 6 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T05:27:38.878Z","repository_id":45290145,"created_at":"2025-08-21T05:27:38.878Z","updated_at":"2025-08-21T05:27:38.878Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28324540,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T18:42:50.174Z","status":"ssl_error","status_checked_at":"2026-01-11T18:39:13.842Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","mutex","primitive","semaphore","semaphore-pattern","synchronization"],"created_at":"2024-07-30T20:01:33.519Z","updated_at":"2026-01-11T21:56:38.306Z","avatar_url":"https://github.com/marusama.png","language":"Go","funding_links":[],"categories":["Misc","Goroutines `goroutines的管理和使用`","Goroutines","Relational Databases"],"sub_categories":["SQL 查询语句构建库","Advanced Console UIs","检索及分析资料库","Search and Analytic Databases"],"readme":"semaphore\n=========\n[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go#goroutines)\n[![Build Status](https://travis-ci.org/marusama/semaphore.svg?branch=master)](https://travis-ci.org/marusama/semaphore)\n[![Go Report Card](https://goreportcard.com/badge/github.com/marusama/semaphore)](https://goreportcard.com/report/github.com/marusama/semaphore)\n[![Coverage Status](https://coveralls.io/repos/github/marusama/semaphore/badge.svg?branch=master)](https://coveralls.io/github/marusama/semaphore?branch=master)\n[![GoDoc](https://godoc.org/github.com/marusama/semaphore?status.svg)](https://godoc.org/github.com/marusama/semaphore)\n[![License](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](LICENSE)\n\nFast resizable golang semaphore based on CAS\n\n* allows weighted acquire/release;\n* supports cancellation via context;\n* allows change semaphore limit after creation;\n* faster than channel based semaphores.\n\n### Usage\nInitiate\n```go\nimport \"github.com/marusama/semaphore/v2\"\n...\nsem := semaphore.New(5) // new semaphore with limit = 5\n```\nAcquire\n```go\nsem.Acquire(ctx, n)     // acquire n with context\nsem.TryAcquire(n)       // try acquire n without blocking \n...\nctx := context.WithTimeout(context.Background(), time.Second)\nsem.Acquire(ctx, n)     // acquire n with timeout\n``` \nRelease\n```go\nsem.Release(n)          // release n\n```\nChange semaphore limit\n```go\nsem.SetLimit(new_limit) // set new semaphore limit\n```\n\n\n### Some benchmarks\nRun on MacBook Pro (2017) with 3,1GHz Core i5 cpu and 8GB DDR3 ram, macOS High Sierra, go version go1.11.4 darwin/amd64:\n```text\n// this semaphore:\nBenchmarkSemaphore_Acquire_Release_under_limit_simple-4                   \t20000000\t        98.6 ns/op\t      96 B/op\t       1 allocs/op\nBenchmarkSemaphore_Acquire_Release_under_limit-4                          \t 1000000\t      1593 ns/op\t     960 B/op\t      10 allocs/op\nBenchmarkSemaphore_Acquire_Release_over_limit-4                           \t  100000\t     20760 ns/op\t    9600 B/op\t     100 allocs/op\n\n\n// some other implementations:\n\n// golang.org/x/sync/semaphore:\nBenchmarkXSyncSemaphore_Acquire_Release_under_limit_simple-4              \t50000000\t        34.9 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkXSyncSemaphore_Acquire_Release_under_limit-4                     \t 1000000\t      1103 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkXSyncSemaphore_Acquire_Release_over_limit-4                      \t   30000\t     65927 ns/op\t   15985 B/op\t     299 allocs/op\n\n// github.com/abiosoft/semaphore:\nBenchmarkAbiosoftSemaphore_Acquire_Release_under_limit_simple-4           \t10000000\t       208 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkAbiosoftSemaphore_Acquire_Release_under_limit-4                  \t  500000\t      3147 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkAbiosoftSemaphore_Acquire_Release_over_limit-4                   \t   50000\t     37148 ns/op\t       0 B/op\t       0 allocs/op\n\n// github.com/dropbox/godropbox\nBenchmarkDropboxBoundedSemaphore_Acquire_Release_under_limit_simple-4     \t20000000\t        75.9 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkDropboxBoundedSemaphore_Acquire_Release_under_limit-4            \t 2000000\t       629 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkDropboxBoundedSemaphore_Acquire_Release_over_limit-4             \t  200000\t     27308 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkDropboxUnboundedSemaphore_Acquire_Release_under_limit_simple-4   \t50000000\t        39.7 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkDropboxUnboundedSemaphore_Acquire_Release_under_limit-4          \t 1000000\t      1170 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkDropboxUnboundedSemaphore_Acquire_Release_over_limit-4           \t  100000\t     21013 ns/op\t       0 B/op\t       0 allocs/op\n\n// github.com/kamilsk/semaphore\nBenchmarkKamilskSemaphore_Acquire_Release_under_limit_simple-4            \t20000000\t       110 ns/op\t      16 B/op\t       1 allocs/op\nBenchmarkKamilskSemaphore_Acquire_Release_under_limit-4                   \t 1000000\t      1520 ns/op\t     160 B/op\t      10 allocs/op\nBenchmarkKamilskSemaphore_Acquire_Release_over_limit-4                    \t   50000\t     42693 ns/op\t    1600 B/op\t     100 allocs/op\n\n// github.com/pivotal-golang/semaphore\nBenchmarkPivotalGolangSemaphore_Acquire_Release_under_limit_simple-4      \t 3000000\t       558 ns/op\t     136 B/op\t       2 allocs/op\nBenchmarkPivotalGolangSemaphore_Acquire_Release_under_limit-4             \t  200000\t      9530 ns/op\t    1280 B/op\t      20 allocs/op\nBenchmarkPivotalGolangSemaphore_Acquire_Release_over_limit-4              \t   10000\t    111264 ns/op\t   12801 B/op\t     200 allocs/op\n\n```\nYou can rerun these benchmarks, just checkout `benchmarks` branch and run `go test -bench=. -benchmem ./bench/...`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarusama%2Fsemaphore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarusama%2Fsemaphore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarusama%2Fsemaphore/lists"}