{"id":18404569,"url":"https://github.com/avakar/intrusive_lfstack","last_synced_at":"2025-08-17T10:34:04.884Z","repository":{"id":137929384,"uuid":"422846320","full_name":"avakar/intrusive_lfstack","owner":"avakar","description":"Lock-free, allocation-free, header-only, composition-based stack for C++11","archived":false,"fork":false,"pushed_at":"2021-10-30T16:16:31.000Z","size":4,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-08-17T10:33:20.476Z","etag":null,"topics":["cpp","lock-free-stack"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avakar.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":"2021-10-30T10:12:43.000Z","updated_at":"2024-10-24T09:01:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"359220b3-4e52-47f9-8bc1-39665031f5b4","html_url":"https://github.com/avakar/intrusive_lfstack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/avakar/intrusive_lfstack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avakar%2Fintrusive_lfstack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avakar%2Fintrusive_lfstack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avakar%2Fintrusive_lfstack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avakar%2Fintrusive_lfstack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avakar","download_url":"https://codeload.github.com/avakar/intrusive_lfstack/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avakar%2Fintrusive_lfstack/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270837403,"owners_count":24654374,"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","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"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":["cpp","lock-free-stack"],"created_at":"2024-11-06T02:53:16.470Z","updated_at":"2025-08-17T10:34:04.838Z","avatar_url":"https://github.com/avakar.png","language":"C++","readme":"# intrusive_lfstack\n\nLock-free, allocation-free, header-only, composition-based stack for C++11.\n\n## Getting started\n\nAdd `lfstack_node` as a member to whatever struct you want to keep in a stack.\nThen, you can push and pop _references_ to that struct.\n\n```cpp\n#include \u003cavakar/intrusive/lfstack.h\u003e\nusing namespace avakar::intrusive;\n\nstruct X {\n    // A node maintains a membership in at most one lfstack.\n    lfstack_node node;\n};\n\nint main()\n{\n    // You must specify the node to be used by each stack.\n    lfstack\u003cX, \u0026X::node\u003e st;\n\n    X x;\n    st.push(x);\n\n    // You can check if a node is pushed in a stack.\n    assert(x.node.attached());\n\n    // If the stack is non-empty, `pop` removes the most recently inserted\n    // element and returns a pointer to it. Otherwise, it returns `nullptr`.\n    X * px = st.pop();\n    assert(px == \u0026x);\n\n    px = st.pop();\n    assert(px == nullptr);\n}\n```\n\nBoth stacks and nodes are immovable.\nIf a node is destroyed while attached, the behavior is undefined.\nClearing or destroying a stack will detach all its nodes.\n\n## Thread-safety\n\nMember functions `lfstack::push`, `lfstack::pop` and `lfstack_node::attached`\ncan be invoked simultaneously without data races. The same holds for\nsimultaneous invocations of `lfstack_node::attached` and the `lfstack`\ndestructor.\n\nA push to `lfstack` synchronizes-with (and therefore happens-before) a pop\nof the corresponding node.\n\nAll operations are lock-free as long as your implementation of `std::atomic`\nhas lock-free DCAS. On amd64 platforms, this requires cmpxchg16b instruction,\nwhich early 64-bit AMD processors didn't have.\nAs of today, MSVC's 64-bit implementation does not support lock-free\nDCAS regardless of your actual processor.\n\nYou can check if lfstack is actually lock-free by checking\n`lfstack::is_lock_free()` or\n`lfstack::is_always_lock_free` (C++17 or newer only).\n\nIn either case, lfstack is thread-safe.\n\n## CMake integration\n\nCopy this repo into yours, add it as a submodule, or `FetchContent` it.\nEither way, make sure this repo is added via `add_subdirectory` or\n`FetchContent_MakeAvailable`, then link against `avakar::intrusive_lfstack`.\n\n    FetchContent(avakar.intrusive_lfstack SOURCE_DIR \"${CMAKE_CURRENT_SOURCE_DIR}/deps/lfstack\")\n    FetchContent_MakeAvailable(avakar.intrusive_lfstack)\n\n    # ...\n    target_link_libraries(mytarget PUBLIC avakar::intrusive_lfstack)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favakar%2Fintrusive_lfstack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favakar%2Fintrusive_lfstack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favakar%2Fintrusive_lfstack/lists"}