{"id":16788443,"url":"https://github.com/sasha-s/go-csync","last_synced_at":"2025-10-15T11:52:50.956Z","repository":{"id":47818251,"uuid":"56112726","full_name":"sasha-s/go-csync","owner":"sasha-s","description":"Golang: contex-aware synchronization primitives (mutex).","archived":false,"fork":false,"pushed_at":"2024-01-07T13:41:40.000Z","size":11,"stargazers_count":32,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T16:57:19.808Z","etag":null,"topics":["context","golang","mutex"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sasha-s.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-13T02:00:38.000Z","updated_at":"2025-01-26T09:03:04.000Z","dependencies_parsed_at":"2024-06-18T18:47:41.247Z","dependency_job_id":null,"html_url":"https://github.com/sasha-s/go-csync","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasha-s%2Fgo-csync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasha-s%2Fgo-csync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasha-s%2Fgo-csync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasha-s%2Fgo-csync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sasha-s","download_url":"https://codeload.github.com/sasha-s/go-csync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841203,"owners_count":20356441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["context","golang","mutex"],"created_at":"2024-10-13T08:17:54.536Z","updated_at":"2025-10-15T11:52:45.909Z","avatar_url":"https://github.com/sasha-s.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-csync\nGolang: [context](https://godoc.org/golang.org/x/net/context)-aware synchronization primitives.\n\nOnly has a mutex right now.\n\ncsync.Mutex can used as a drop-in replacement for the [sync.Mutex](https://golang.org/pkg/sync/#Mutex), or with a context, like this:\n\n```go\nvar mu csync.Mutex\n...\nfunc (...) {\n\tctx, cf := context.WithTimeout(context.Background(), time.Second)\n\tif mu.CLock(ctx) != nil {\n\t\t// Failed to lock.\n\t\treturn err\n\t}\n\tdefer mu.Unlock()\n\t// Do stuff.\n}\n```\n\n## Benchstat\nOn my MacBook Pro:\n\nComparing [regular mutex](https://golang.org/pkg/sync/#Mutex) to this implementation:\nNote, this benchmarks the Lock function.\n\n```\nname                old time/op  new time/op  delta\nMutexUncontended-8  3.73ns ± 0%  4.43ns ±10%  +18.90%  (p=0.016 n=4+5)\nMutex-8             96.8ns ± 2%  38.6ns ±14%  -60.10%  (p=0.008 n=5+5)\nMutexSlack-8         125ns ± 3%    45ns ±14%  -64.12%  (p=0.008 n=5+5)\nMutexWork-8          113ns ± 3%   105ns ± 8%     ~     (p=0.095 n=5+5)\nMutexWorkSlack-8     149ns ± 7%   103ns ± 5%  -30.97%  (p=0.008 n=5+5)\nMutexNoSpin-8        258ns ±10%   281ns ± 7%     ~     (p=0.111 n=5+5)\nMutexSpin-8         1.23µs ± 9%  1.25µs ± 5%     ~     (p=1.000 n=5+5)\n```\n\nClock benchmarks:\nNote, this benchmars CLock function. Slightly worse than Lock.\n\n```\nCMutexUncontended-8         5.59ns ± 9%\nCMutexUncontendedTimeout-8  5.38ns ±10%\nCMutex-8                    45.1ns ± 6%\nCMutexSlack-8               48.8ns ± 6%\nCMutexWork-8                 110ns ± 5%\nCMutexWorkSlack-8            107ns ± 7%\nCMutexNoSpin-8               301ns ±19%\nCMutexSpin-8                1.25µs ± 9%\nCMutexTimeout-8             26.9ns ± 6%\nCMutexSlackTimeout-8        44.2ns ± 3%\nCMutexWorkTimeout-8          109ns ± 6%\nCMutexWorkSlackTimeout-8     109ns ± 5%\nCMutexNoSpinTimeout-8        294ns ± 8%\nCMutexSpinTimeout-8         1.30µs ±11%\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsasha-s%2Fgo-csync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsasha-s%2Fgo-csync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsasha-s%2Fgo-csync/lists"}