{"id":34897125,"url":"https://github.com/soenneker/soenneker.asyncs.locks","last_synced_at":"2026-06-06T01:03:19.417Z","repository":{"id":329663897,"uuid":"1120069872","full_name":"soenneker/soenneker.asyncs.locks","owner":"soenneker","description":"The fastest .NET async lock","archived":false,"fork":false,"pushed_at":"2026-05-29T00:53:40.000Z","size":213,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-29T02:24:29.805Z","etag":null,"topics":["async","asynclock","asyncs","csharp","dotnet","gate","initialization","locks","mutex","semaphore","semaphoreslim","util"],"latest_commit_sha":null,"homepage":"https://soenneker.com","language":"C#","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/soenneker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"soenneker","thanks_dev":"soenneker"}},"created_at":"2025-12-20T12:28:41.000Z","updated_at":"2026-05-22T09:53:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"24fc4cd9-a0c4-4673-acd9-0507ef5481df","html_url":"https://github.com/soenneker/soenneker.asyncs.locks","commit_stats":null,"previous_names":["soenneker/soenneker.asyncs.locks"],"tags_count":45,"template":false,"template_full_name":null,"purl":"pkg:github/soenneker/soenneker.asyncs.locks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.asyncs.locks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.asyncs.locks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.asyncs.locks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.asyncs.locks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soenneker","download_url":"https://codeload.github.com/soenneker/soenneker.asyncs.locks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.asyncs.locks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33964367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-05T02:00:06.157Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["async","asynclock","asyncs","csharp","dotnet","gate","initialization","locks","mutex","semaphore","semaphoreslim","util"],"created_at":"2025-12-26T07:37:13.039Z","updated_at":"2026-06-06T01:03:19.411Z","avatar_url":"https://github.com/soenneker.png","language":"C#","funding_links":["https://github.com/sponsors/soenneker","https://thanks.dev/soenneker"],"categories":[],"sub_categories":[],"readme":"[![](https://img.shields.io/nuget/v/soenneker.asyncs.locks.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.asyncs.locks/)\n[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.asyncs.locks/publish-package.yml?style=for-the-badge)](https://github.com/soenneker/soenneker.asyncs.locks/actions/workflows/publish-package.yml)\n[![](https://img.shields.io/nuget/dt/soenneker.asyncs.locks.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.asyncs.locks/)\n[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.asyncs.locks/codeql.yml?label=CodeQL\u0026style=for-the-badge)](https://github.com/soenneker/soenneker.asyncs.locks/actions/workflows/codeql.yml)\n\n# Soenneker.Asyncs.Locks\n### The fastest .NET async lock\n\nThis library provides a single primitive: `AsyncLock`.\n\n### Design goal\n\n`AsyncLock` is built to be the **fastest possible correct mutex** for real-world .NET systems.\n\nIt provides the following guarantees:\n\n#### Cancellation-safe\n\n- Fully supports cancellation before acquisition and while waiting for both async and sync callers.  \n- Cancelled waiters are removed immediately, never resumed, and never leaked � with **zero impact on the fast path**.\n\n#### Unified async + sync locking\n\n- Async and synchronous callers share the *same mutex*.  \n- Ordering is preserved without adapters, wrappers, or duplicated synchronization primitives.\n\n#### Performance (by design)\n\n- Uncontended acquisition is as close to a single atomic operation as possible\n- No allocations, tasks, or state machines unless contention occurs\n- Cancellation and disposal logic are completely excluded from the fast path\n- Deterministic behavior under contention\n\n---\n\n## Installation\n\n```bash\ndotnet add package Soenneker.Asyncs.Locks\n```\n\n---\n\n## Usage\n\n### Async\n\n```csharp\nawait using (await _lock.Lock(ct))\n{\n    // critical section\n}\n```\n\n### Sync\n\n```csharp\nusing (_lock.LockSync())\n{\n    // critical section\n}\n```\n\n### Try-lock\n\n```csharp\nif (_lock.TryLock(out var releaser))\n{\n    using (releaser)\n    {\n        // critical section\n    }\n}\n```\n\n---\n\n## Benchmarks\n\n### Async lock acquisition\n\n| Method                    |     Mean |    Error |   StdDev |   Median |        Ratio | Allocated |\n| ------------------------- | -------: | -------: | -------: | -------: | -----------: | --------: |\n| **Soenneker.Asyncs.Lock** | 10.06 ns | 0.212 ns | 0.393 ns | 10.01 ns |     baseline |         - |\n| SemaphoreSlim             | 19.17 ns | 0.406 ns | 0.360 ns | 19.10 ns | 1.91x slower |         - |\n| Nito.AsyncEx.AsyncLock    | 55.32 ns | 1.078 ns | 2.645 ns | 54.81 ns | 5.51x slower |     320 B |\n\n---\n\n### Synchronous lock acquisition\n\n| Method                    |     Mean |    Error |   StdDev |   Median |        Ratio | Allocated |\n| ------------------------- | -------: | -------: | -------: | -------: | -----------: | --------: |\n| **Soenneker.Asyncs.Lock** |  8.09 ns | 0.179 ns | 0.314 ns |  8.03 ns |     baseline |         - |\n| SemaphoreSlim             | 19.49 ns | 0.403 ns | 0.727 ns | 19.09 ns | 2.41x slower |         - |\n| Nito.AsyncEx.AsyncLock    | 48.43 ns | 1.005 ns | 2.915 ns | 48.05 ns | 6.00x slower |     320 B |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoenneker%2Fsoenneker.asyncs.locks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoenneker%2Fsoenneker.asyncs.locks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoenneker%2Fsoenneker.asyncs.locks/lists"}