{"id":20191410,"url":"https://github.com/htfy96/seqlock","last_synced_at":"2025-06-17T20:41:59.530Z","repository":{"id":86702038,"uuid":"189933690","full_name":"htfy96/seqlock","owner":"htfy96","description":"A C++11 SeqLock implementation with reader/writer support, designed for non-blocking reads","archived":false,"fork":false,"pushed_at":"2019-06-04T05:09:14.000Z","size":19,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-03T07:41:35.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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/htfy96.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":"2019-06-03T04:21:33.000Z","updated_at":"2025-01-16T17:49:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"4146473b-e976-4dc2-9fc8-e451e5529508","html_url":"https://github.com/htfy96/seqlock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/htfy96/seqlock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Fseqlock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Fseqlock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Fseqlock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Fseqlock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/htfy96","download_url":"https://codeload.github.com/htfy96/seqlock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Fseqlock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260439066,"owners_count":23009269,"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-11-14T03:48:47.523Z","updated_at":"2025-06-17T20:41:54.516Z","avatar_url":"https://github.com/htfy96.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# seqlock\nA C++11 SeqLock implementation with reader/writer support, designed for non-blocking reads.\n\n![GitHub](https://img.shields.io/github/license/htfy96/seqlock.svg) [![CircleCI](https://circleci.com/gh/htfy96/seqlock.svg?style=svg\u0026circle-token=17626543a8bc4d2f5ee0beba9b78c66ca3540c09)](https://circleci.com/gh/htfy96/seqlock)\n\n\n\n## Usage\n```cpp\n#include \"seqlock.hpp\"\n\nstruct Foo {\n    int v1;\n    double v2;\n    long v3;\n};\n\n// Basic usage:\nusing namespace seqlock;\nSeqLock\u003cFoo\u003e protected_data {2, 3.0};\n\nprotected_data.write(foo_1); // thread-safe. No serialization.\nFoo data = protected_data.load(); // does not block write, thread-safe\n\n// Advanced usage:\n// mainly used for large structs to avoid copy\n{\n    auto writer = protected_data.get_writer(); // move-only\n    // exclusive access\n    auto old_value = writer.read_member(\u0026Foo::v);\n    writer.write_member(\u0026Foo::v, old_value + 2);\n    // writer lock will be automatically released at the exit of scope\n}\n\nstd::tuple\u003cint, long\u003e v1_and_v3 = protected_data.load_members(\u0026Foo::v1, \u0026Foo::v3);\n```\n\n\nA seqlock is a writer-first userspace lock.\nReader doesn't block writers by retrying read based on version numbers.\n\nUse cases:\n- busy writer(s)\n- a small number of writers\n- starvation between writers can be tolerated\n- non-blocking reads\n\n```cpp\ntemplate \u003ctypename T,\n          typename ReadConflictPolicy = conflict_policies::Auto,\n          typename WriteConflictPolicy = conflict_policies::Auto,\n          typename SeqCounterT = std::uint_fast32_t\u003e\nclass SeqLock;\n```\n\nPrecondition: `is_trivial\u003cT\u003e`\n\nConfig:\n- `T`: protected data, must be TrivialType\n- `ReadConflictPolicy`: Behavior when load() finds another thread writing the\nvalue.\n  Default: `conflict_policies::Auto`.\n- `WriteConflictPolicy`: Behavior when store() finds another thread writing\nthe value.\n  Default: `conflict_policies::Auto`.\n- `SeqCounterT`: the sequence counter. Set this to a larger type if there are\ntoo many writers causing it to wrap around.\n\nImplementation based on: *Can Seqlocks Get Along with Programming Language\nMemory Models?, Hans-J. Boehm HP Labs*\n\n`conflict_policies`:\n- `Pause`: use x86 instruction `pause` on conflict\n- `Yield`: yield to another thread\n- `RetryImmediately`: no-op\n- `Auto`: use `Pause` when possible, `Yield` otherwise\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhtfy96%2Fseqlock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhtfy96%2Fseqlock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhtfy96%2Fseqlock/lists"}