{"id":16092292,"url":"https://github.com/alecthomas/atomic","last_synced_at":"2025-06-30T10:36:08.337Z","repository":{"id":57658508,"uuid":"434786388","full_name":"alecthomas/atomic","owner":"alecthomas","description":"Type-safe atomic values for Go","archived":false,"fork":false,"pushed_at":"2023-12-02T11:37:40.000Z","size":10,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T08:35:59.330Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/alecthomas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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":"2021-12-04T02:18:41.000Z","updated_at":"2024-01-28T07:25:13.000Z","dependencies_parsed_at":"2024-06-19T00:03:41.420Z","dependency_job_id":"770164d9-c45f-4eb9-b896-a50157cd8e6d","html_url":"https://github.com/alecthomas/atomic","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"3bb2dce55f91981f61053c690d553952e448863d"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/alecthomas/atomic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fatomic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fatomic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fatomic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fatomic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alecthomas","download_url":"https://codeload.github.com/alecthomas/atomic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fatomic/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262756841,"owners_count":23359590,"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":[],"created_at":"2024-10-09T16:06:47.474Z","updated_at":"2025-06-30T10:36:08.308Z","avatar_url":"https://github.com/alecthomas.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Type-safe atomic values for Go\n\nOne issue with Go's sync/atomic package is that there is no guarantee from the\ntype system that operations on an integer value will be applied through the\nsync/atomic functions. This package solves that and introduces two type-safe\ninterfaces for use with integer and non-integer atomic values.\n\nThe first interface is for any value:\n\n```go\n// Interface represents a value that can be atomically loaded or replaced.\ntype Interface[T any] interface {\n\t// Load value atomically.\n\tLoad() T\n\t// Store value atomically.\n\tStore(value T)\n\t// Swap the previous value with the new value atomically.\n\tSwap(new T) (old T)\n\t// CompareAndSwap the previous value with new if its value is \"old\".\n\tCompareAndSwap(old, new T) (swapped bool)\n}\n```\n\nThe second interface is a `Value[T]` constrained to the 32 and 64 bit integer\ntypes and adds a single `Add()` method:\n\n```go\n// Int expresses atomic operations on signed or unsigned integer values.\ntype Int[T atomicint] interface {\n\tValue[T]\n\t// Add a value and return the new result.\n\tAdd(delta T) (new T)\n}\n\n```\n\n## Performance\n\n```\nBenchmarkInt64Add\nBenchmarkInt64Add-8           \t174217112\t        6.887 ns/op\nBenchmarkIntInterfaceAdd\nBenchmarkIntInterfaceAdd-8    \t174129980\t        6.889 ns/op\nBenchmarkStdlibInt64Add\nBenchmarkStdlibInt64Add-8     \t174152660\t        6.887 ns/op\nBenchmarkInterfaceStore\nBenchmarkInterfaceStore-8     \t16015668\t       76.17 ns/op\nBenchmarkValueStore\nBenchmarkValueStore-8         \t16155405\t       75.03 ns/op\nBenchmarkStdlibValueStore\nBenchmarkStdlibValueStore-8   \t16391035\t       74.85 ns/op\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falecthomas%2Fatomic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falecthomas%2Fatomic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falecthomas%2Fatomic/lists"}