{"id":13424407,"url":"https://github.com/lewissbaker/disruptorplus","last_synced_at":"2025-05-01T14:32:05.292Z","repository":{"id":19213858,"uuid":"22447836","full_name":"lewissbaker/disruptorplus","owner":"lewissbaker","description":"A disruptor thread-synchronisation data structure for C++11.","archived":false,"fork":false,"pushed_at":"2023-05-26T11:01:39.000Z","size":51,"stargazers_count":118,"open_issues_count":3,"forks_count":37,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-10-26T23:55:12.763Z","etag":null,"topics":["c-plus-plus","disruptor","synchronisation"],"latest_commit_sha":null,"homepage":null,"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/lewissbaker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-07-30T22:52:46.000Z","updated_at":"2024-07-22T09:30:21.000Z","dependencies_parsed_at":"2024-01-28T09:52:49.549Z","dependency_job_id":null,"html_url":"https://github.com/lewissbaker/disruptorplus","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/lewissbaker%2Fdisruptorplus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewissbaker%2Fdisruptorplus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewissbaker%2Fdisruptorplus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewissbaker%2Fdisruptorplus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lewissbaker","download_url":"https://codeload.github.com/lewissbaker/disruptorplus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224262021,"owners_count":17282267,"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":["c-plus-plus","disruptor","synchronisation"],"created_at":"2024-07-31T00:00:53.952Z","updated_at":"2024-11-12T11:12:23.866Z","avatar_url":"https://github.com/lewissbaker.png","language":"C++","funding_links":[],"categories":["Concurrency"],"sub_categories":[],"readme":"Disruptor++\n===========\n\nDisruptor++ is a C++11 header-only implementation of the 'disruptor' data structure used\nto communicate between threads in a high-performance producer/consumer arrangement.\n\nSee the LMAX [technical paper](https://lmax-exchange.github.io/disruptor/files/Disruptor-1.0.pdf)\nfor a description of the theory behind the disruptor.\n\nSee the [Java LMAX Disruptor project](http://lmax-exchange.github.io/disruptor/) for\nmore resources relating to the disruptor.\n\nDescription\n-----------\n\nA disruptor data structure is essentially a ring buffer that uses different cursors\nto keep track of where consumers or producers have processed up to.\n\nA disruptor can be used with either single producer thread or multiple producer\nthreads. Multiple producer threads are able to publish items out-of-sequence\nso that producer threads do not hold up other producer threads unless the\nentire ring buffer fills up while waiting for a slow producer to publish its item.\nConsumers, however, always process items in the sequence they were enqueued.\n\nThe disruptor data structure supports batched operations with producers able to\nenqueue multiple items with a single synchronisation operation and consumers\nthat fall behind are able to catch up by consuming batches of consecutive\nitems with a single synchronisation operation.\n\nWhen used with a single producer thread with the spin wait-strategy the disruptor\nuses only atomic reads/writes of integers and acquire/release memory barriers for\nsynchronisation. It does not use CAS operations or locks that require kernel\narbitration.\n\nThis implementation of the disruptor data-structure is defined fully in header files.\nThere are no libraries to link against and many functions should be able to be inlined.\nAlso, this implementation does not make use of abstract interfaces or virtual function\ncalls, which can inhibit inlining and incur additional runtime overhead, but instead\nprefers to use templates for compile-time polymorphism.\n\nPerformance\n-----------\n\nTODO: Put some performance results in here.\n\nSynopsis\n--------\n\nA single producer/single consumer use of a disruptor for communication.\n\n```\n#include \u003cdisruptorplus/ring_buffer.hpp\u003e\n#include \u003cdisruptorplus/single_threaded_claim_strategy.hpp\u003e\n#include \u003cdisruptorplus/spin_wait_strategy.hpp\u003e\n#include \u003cdisruptorplus/sequence_barrier.hpp\u003e\n\n#include \u003cthread\u003e\n\nusing namespace disruptorplus;\n\nstruct Event\n{\n    uint32_t data;\n};\n\nint main()\n{\n    const size_t bufferSize = 1024; // Must be power-of-two\n    \n    ring_buffer\u003cEvent\u003e buffer(bufferSize);\n    \n    spin_wait_strategy waitStrategy;\n    single_threaded_claim_strategy\u003cspin_wait_strategy\u003e claimStrategy(bufferSize, waitStrategy);\n    sequence_barrier\u003cspin_wait_strategy\u003e consumed(waitStrategy);\n    claimStrategy.add_claim_barrier(consumed);\n    \n    std::thread consumer([\u0026]()\n    {\n        uint64_t sum = 0;\n        sequence_t nextToRead = 0;\n        bool done = false;\n        while (!done)\n        {\n            // Wait until more items available\n            sequence_t available = claimStrategy.wait_until_published(nextToRead);\n            \n            // Process all available items in a batch\n            do\n            {\n                auto\u0026 event = buffer[nextToRead];\n                sum += event.data;\n                if (event.data == 0)\n                {\n                    done = true;\n                }\n            } while (nextToRead++ != available);\n            \n            // Notify producer we've finished consuming some items\n            consumed.publish(available);\n        }\n        std::cout \u003c\u003c \"sum is \" \u003c\u003c sum \u003c\u003c std::endl;\n    });\n    \n    std::thread producer([\u0026]()\n    {\n        for (uint32_t i = 1; i \u003c= 1000000; ++i)\n        {\n            // Claim a slot in the ring buffer, waits if buffer is full\n            sequence_t seq = claimStrategy.claim_one();\n            \n            // Write to the slot in the ring buffer\n            buffer[seq].data = i;\n            \n            // Publish the event to the consumer\n            claimStrategy.publish(seq);\n        }\n        \n        // Publish the terminating event.\n        sequence_t seq = claimStrategy.claim_one():\n        buffer[seq].data = 0;\n        claimStrategy.publish(seq);\n    });\n    \n    consumer.join();\n    producer.join();\n    \n    return 0;\n}\n```\n\nLicense\n-------\n\nThe Discruptor++ library is available under the MIT open source license.\nSee LICENSE.txt for details.\n\nBuilding\n--------\n\nAs this library is a header-only library there is no library component\nthat needs to be built separately. Simply add the include/ directory\nto your include path and include the appropriate headers.\n\nIf you want to build the samples/tests then you can use the\n[Cake](https://github.com/lewissbaker/cake) build system to build\nthis code.\n\nOnce you have installed cake you can simply run 'cake' in the root\ndirectory to build everything.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flewissbaker%2Fdisruptorplus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flewissbaker%2Fdisruptorplus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flewissbaker%2Fdisruptorplus/lists"}