{"id":17252041,"url":"https://github.com/ppetr/lockfree-userspace-rcu","last_synced_at":"2025-09-02T22:39:23.744Z","repository":{"id":146160480,"uuid":"451397204","full_name":"ppetr/lockfree-userspace-rcu","owner":"ppetr","description":"Lock-free RCU (Read-Copy-Update) user-space library","archived":false,"fork":false,"pushed_at":"2023-10-06T16:45:43.000Z","size":47822,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-16T06:52:57.740Z","etag":null,"topics":["cpp","lock-free","rcu","userspace"],"latest_commit_sha":null,"homepage":"","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/ppetr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":"docs/code-of-conduct.md","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":"2022-01-24T09:24:55.000Z","updated_at":"2024-09-15T18:25:51.000Z","dependencies_parsed_at":"2024-10-15T06:52:56.379Z","dependency_job_id":"1cac8221-0a2f-4639-9156-4dc506d0d6d7","html_url":"https://github.com/ppetr/lockfree-userspace-rcu","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppetr%2Flockfree-userspace-rcu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppetr%2Flockfree-userspace-rcu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppetr%2Flockfree-userspace-rcu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppetr%2Flockfree-userspace-rcu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ppetr","download_url":"https://codeload.github.com/ppetr/lockfree-userspace-rcu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228042493,"owners_count":17860428,"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":["cpp","lock-free","rcu","userspace"],"created_at":"2024-10-15T06:52:53.382Z","updated_at":"2024-12-04T04:21:16.417Z","avatar_url":"https://github.com/ppetr.png","language":"C++","readme":"# Simple and fast user-space [RCU](Read-Copy-Update)[^1] library\n\n[RCU]: https://en.wikipedia.org/wiki/Read-copy-update\n\n[^1]: If you like RCU, you might also like [rCUP](https://circularandco.com/shop/reusables/circular-reusable-coffee-cup) - a reusable coffee cup made from recycled single-use paper cups.\n\n_*Disclaimer:* This is not an officially supported Google product._\n\n[![Build Status](https://app.travis-ci.com/ppetr/lockfree-userspace-rcu.svg?branch=main)](https://app.travis-ci.com/ppetr/lockfree-userspace-rcu)\n\n## Usage\n\n```c++\n#include \"simple_rcu/rcu.h\"\n\n// Shared object that provides an instance of `MyType`:\nauto rcu = std::make_shared\u003csimple_rcu::Rcu\u003cMyType\u003e\u003e();\n\n// Any thread can atomically update the value (can be also a `unique_ptr`,\n// which auto-converts to `shared_ptr`). This is a relatively slow operation\n// (takes a lock internally).\nrcu-\u003eUpdate(std::make_shared\u003cMyType\u003e(...));\n```\n\n### Simple\n\n```c++\n// Afterwards each reader thread can fetch a const pointer to a snapshot of the\n// instance. This is a lock-free operation.\n// See benchmark `BM_ReadSharedPtrsThreadLocal` below.\nauto ref = simple_rcu::ReadPtr(rcu);\n// `ref` now holds a `unique_ptr` to a stable, thread-local snapshot of\n// `const MyType`.\n```\n\n### Advanced\n\n```c++\n// Each reader thread creates a local accessor to `rcu`, which will hold\n// snapshots of `MyType`.\nsimple_rcu::Rcu\u003cMyType\u003e::View local(rcu);\n\n// Afterwards the reader thread can repeatedly fetch a const pointer to a\n// snapshot of the instance. This is faster than the simple usage above (see\n// benchmark `BM_Reads` below), since it avoids the internal bookkeeping cost of a\n// `thread_local` variable, at the cost of explicitly maintaining a `View`\n// variable. It effectively involves only a single atomic exchange\n// (https://en.cppreference.com/w/cpp/atomic/atomic/exchange) instruction.\nauto ref = local.ReadPtr();\n// `ref` now holds a `unique_ptr` to a stable, thread-local snapshot of\n// `const MyType`.\n```\n\nSee [copy_rcu_test.cc](simple_rcu/copy_rcu_test.cc) for more examples.\n\n## Dependencies\n\n- `cmake` (https://cmake.org/).\n- https://github.com/abseil/abseil-cpp (Git submodule)\n\nTesting dependencies:\n\n- https://github.com/google/benchmark (Git submodule)\n- https://github.com/google/googletest (Git submodule)\n\n## Benchmarks\n\nThe numbers `/1/` or `/4/` after a benchmark name denote the number of\nconcurrent running threads performing the opposite operation - updates when\nbenchmarking reads and vice versa.\n\nAs shown below, **reads** are very fast and their performance suffers neither\nfrom running concurrent read (1 to 3) nor update (1 or 4) threads. In fact\nrunning multiple read operations benefits from CPU caching.\n\n**Updates** are much slower, as expected. Since (unlike reads) they acquire a\nstandard [mutex](https://abseil.io/docs/cpp/guides/synchronization), lock\ncontention occurs when there are multiple concurrent update operations. Also,\nwhen there are multiple concurrent readers, updates become slower, since they\nneed to distribute values to the readers' thread-local copies.\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ccode\u003eg++\u003c/code\u003e on Core i5:\u003c/dt\u003e\n  \u003cdd\u003e\n    \u003cpre\u003e\n2023-03-08T19:37:57+01:00\nRunning build/rel-gcc/simple_rcu/copy_rcu_benchmark\nRun on (4 X 3572.69 MHz CPU s)\nCPU Caches:\n  L1 Data 32 KiB (x4)\n  L1 Instruction 32 KiB (x4)\n  L2 Unified 256 KiB (x4)\n  L3 Unified 6144 KiB (x1)\nLoad Average: 0.33, 1.50, 1.26\n------------------------------------------------------------------------------------\nBenchmark                                          Time             CPU   Iterations\n------------------------------------------------------------------------------------\nBM_Reads/1/threads:1                            88.0 ns         88.0 ns      7925289\nBM_Reads/1/threads:2                            17.7 ns         35.4 ns     21247450\nBM_Reads/1/threads:4                            6.64 ns         22.5 ns     35341128\nBM_Reads/1/threads:8                            2.30 ns         10.1 ns     61592216\nBM_Reads/1/threads:16                           1.58 ns         7.43 ns     87989696\nBM_Reads/1/threads:32                           1.27 ns         6.74 ns     94589952\nBM_Reads/1/threads:64                          0.841 ns         6.64 ns    106161024\nBM_Reads/4/threads:1                            84.3 ns         84.3 ns     11161830\nBM_Reads/4/threads:2                            6.84 ns         13.7 ns     39595196\nBM_Reads/4/threads:4                            4.89 ns         15.8 ns     55958100\nBM_Reads/4/threads:8                            2.11 ns         8.99 ns     69275648\nBM_Reads/4/threads:16                           1.59 ns         7.79 ns     67754640\nBM_Reads/4/threads:32                           1.49 ns         7.00 ns     98964928\nBM_Reads/4/threads:64                          0.735 ns         6.54 ns    103060736\nBM_ReadSharedPtrs/1/threads:1                   62.9 ns         62.9 ns     11343017\nBM_ReadSharedPtrs/1/threads:2                   12.4 ns         24.9 ns     28810718\nBM_ReadSharedPtrs/1/threads:4                   4.03 ns         13.6 ns     47565036\nBM_ReadSharedPtrs/1/threads:8                   2.02 ns         8.41 ns     73046840\nBM_ReadSharedPtrs/1/threads:16                  1.62 ns         7.22 ns     96594224\nBM_ReadSharedPtrs/1/threads:32                  1.37 ns         6.76 ns     98965440\nBM_ReadSharedPtrs/1/threads:64                 0.925 ns         6.57 ns    102769984\nBM_ReadSharedPtrs/4/threads:1                   50.0 ns         50.0 ns     10000000\nBM_ReadSharedPtrs/4/threads:2                   5.64 ns         11.2 ns     56381504\nBM_ReadSharedPtrs/4/threads:4                   3.83 ns         11.2 ns     45073088\nBM_ReadSharedPtrs/4/threads:8                   2.17 ns         8.11 ns     78239648\nBM_ReadSharedPtrs/4/threads:16                  1.72 ns         7.28 ns     89113344\nBM_ReadSharedPtrs/4/threads:32                  1.46 ns         6.82 ns     99200224\nBM_ReadSharedPtrs/4/threads:64                  1.02 ns         6.52 ns    104567680\nBM_ReadSharedPtrsThreadLocal/1/threads:1         101 ns          101 ns      6553118\nBM_ReadSharedPtrsThreadLocal/1/threads:2        51.5 ns          103 ns      6001084\nBM_ReadSharedPtrsThreadLocal/1/threads:4        41.2 ns          134 ns      5285084\nBM_ReadSharedPtrsThreadLocal/1/threads:8        35.4 ns          138 ns      5366944\nBM_ReadSharedPtrsThreadLocal/1/threads:16       26.3 ns          128 ns      5000608\nBM_ReadSharedPtrsThreadLocal/1/threads:32       28.3 ns          142 ns      5779744\nBM_ReadSharedPtrsThreadLocal/1/threads:64       19.2 ns          126 ns      5579776\nBM_ReadSharedPtrsThreadLocal/4/threads:1         113 ns          113 ns      5932706\nBM_ReadSharedPtrsThreadLocal/4/threads:2        64.4 ns          129 ns      5636694\nBM_ReadSharedPtrsThreadLocal/4/threads:4        45.8 ns          129 ns      4000000\nBM_ReadSharedPtrsThreadLocal/4/threads:8        34.4 ns          127 ns      5632464\nBM_ReadSharedPtrsThreadLocal/4/threads:16       28.4 ns          121 ns      4951344\nBM_ReadSharedPtrsThreadLocal/4/threads:32       33.7 ns          139 ns      5735200\nBM_ReadSharedPtrsThreadLocal/4/threads:64       25.9 ns          137 ns      6150656\nBM_Updates/1/threads:1                           126 ns          126 ns      5545689\nBM_Updates/1/threads:2                           136 ns          271 ns      2289246\nBM_Updates/1/threads:4                           133 ns          320 ns      1883372\nBM_Updates/1/threads:8                           114 ns          145 ns      3911272\nBM_Updates/1/threads:16                         98.1 ns          138 ns      5120464\nBM_Updates/1/threads:32                         92.4 ns          146 ns      3935488\nBM_Updates/1/threads:64                         73.1 ns          141 ns      4169792\nBM_Updates/4/threads:1                           394 ns          310 ns      2319023\nBM_Updates/4/threads:2                           320 ns          403 ns      1572682\nBM_Updates/4/threads:4                           347 ns          460 ns      2120880\nBM_Updates/4/threads:8                           317 ns          337 ns      2066568\nBM_Updates/4/threads:16                          279 ns          341 ns      1708928\nBM_Updates/4/threads:32                          265 ns          330 ns      2127232\nBM_Updates/4/threads:64                          233 ns          321 ns      2190336\n    \u003c/pre\u003e\n  \u003c/dd\u003e\n\u003cdt\u003e\u003ccode\u003eclang++11\u003c/code\u003e on Core i5:\u003c/dt\u003e\n  \u003cdd\u003e\n    \u003cpre\u003e\n2023-03-08T19:38:30+01:00\nRunning build/rel-clang11/simple_rcu/copy_rcu_benchmark\nRun on (4 X 1694.88 MHz CPU s)\nCPU Caches:\n  L1 Data 32 KiB (x4)\n  L1 Instruction 32 KiB (x4)\n  L2 Unified 256 KiB (x4)\n  L3 Unified 6144 KiB (x1)\nLoad Average: 4.90, 2.46, 1.58\n------------------------------------------------------------------------------------\nBenchmark                                          Time             CPU   Iterations\n------------------------------------------------------------------------------------\nBM_Reads/1/threads:1                            87.7 ns         87.7 ns      7955889\nBM_Reads/1/threads:2                            15.3 ns         30.6 ns     23136186\nBM_Reads/1/threads:4                            7.42 ns         25.2 ns     28852784\nBM_Reads/1/threads:8                            2.81 ns         12.1 ns     48782816\nBM_Reads/1/threads:16                           1.43 ns         7.65 ns     70177200\nBM_Reads/1/threads:32                           1.33 ns         6.80 ns     97955488\nBM_Reads/1/threads:64                          0.952 ns         6.61 ns     98974848\nBM_Reads/4/threads:1                            58.5 ns         58.5 ns      9621076\nBM_Reads/4/threads:2                            8.63 ns         17.2 ns     39341958\nBM_Reads/4/threads:4                            6.68 ns         20.9 ns     49974640\nBM_Reads/4/threads:8                            4.36 ns         15.6 ns     46642208\nBM_Reads/4/threads:16                           1.78 ns         8.27 ns     68227440\nBM_Reads/4/threads:32                           1.35 ns         7.09 ns     94126560\nBM_Reads/4/threads:64                          0.876 ns         6.91 ns     99590016\nBM_ReadSharedPtrs/1/threads:1                   63.4 ns         63.4 ns     11204514\nBM_ReadSharedPtrs/1/threads:2                   12.6 ns         25.2 ns     20000000\nBM_ReadSharedPtrs/1/threads:4                   5.01 ns         16.4 ns     38396812\nBM_ReadSharedPtrs/1/threads:8                   2.87 ns         11.9 ns     61796344\nBM_ReadSharedPtrs/1/threads:16                  2.02 ns         9.59 ns     78273408\nBM_ReadSharedPtrs/1/threads:32                  1.48 ns         7.91 ns     80529600\nBM_ReadSharedPtrs/1/threads:64                  1.25 ns         10.6 ns     56653504\nBM_ReadSharedPtrs/4/threads:1                   63.8 ns         63.8 ns     10000000\nBM_ReadSharedPtrs/4/threads:2                   5.83 ns         11.6 ns     68954404\nBM_ReadSharedPtrs/4/threads:4                   4.44 ns         13.9 ns     58391728\nBM_ReadSharedPtrs/4/threads:8                   2.75 ns         11.3 ns     53274936\nBM_ReadSharedPtrs/4/threads:16                  2.66 ns         10.8 ns     93864160\nBM_ReadSharedPtrs/4/threads:32                  2.44 ns         10.4 ns     64900896\nBM_ReadSharedPtrs/4/threads:64                 0.823 ns         7.14 ns     77218560\nBM_ReadSharedPtrsThreadLocal/1/threads:1         134 ns          134 ns      5011638\nBM_ReadSharedPtrsThreadLocal/1/threads:2        70.4 ns          141 ns      6701984\nBM_ReadSharedPtrsThreadLocal/1/threads:4        43.2 ns          136 ns      4510720\nBM_ReadSharedPtrsThreadLocal/1/threads:8        41.4 ns          160 ns      5049376\nBM_ReadSharedPtrsThreadLocal/1/threads:16       35.2 ns          146 ns      4635376\nBM_ReadSharedPtrsThreadLocal/1/threads:32       32.4 ns          149 ns      4752544\nBM_ReadSharedPtrsThreadLocal/1/threads:64       18.8 ns          146 ns      5139008\nBM_ReadSharedPtrsThreadLocal/4/threads:1         156 ns          156 ns      4373200\nBM_ReadSharedPtrsThreadLocal/4/threads:2        84.6 ns          159 ns      4440214\nBM_ReadSharedPtrsThreadLocal/4/threads:4        54.2 ns          155 ns      4642584\nBM_ReadSharedPtrsThreadLocal/4/threads:8        44.2 ns          147 ns      4755640\nBM_ReadSharedPtrsThreadLocal/4/threads:16       34.9 ns          147 ns      5078864\nBM_ReadSharedPtrsThreadLocal/4/threads:32       37.0 ns          152 ns      4980928\nBM_ReadSharedPtrsThreadLocal/4/threads:64       23.4 ns          149 ns      4204736\nBM_Updates/1/threads:1                           129 ns          129 ns      5429974\nBM_Updates/1/threads:2                           205 ns          410 ns      1625164\nBM_Updates/1/threads:4                           134 ns          155 ns      3337368\nBM_Updates/1/threads:8                           112 ns          138 ns      3871216\nBM_Updates/1/threads:16                         96.5 ns          142 ns      4074256\nBM_Updates/1/threads:32                         96.9 ns          142 ns      3858176\nBM_Updates/1/threads:64                         75.3 ns          147 ns      4228096\nBM_Updates/4/threads:1                           422 ns          339 ns      2059096\nBM_Updates/4/threads:2                           464 ns          412 ns      1585970\nBM_Updates/4/threads:4                           412 ns          419 ns      1312416\nBM_Updates/4/threads:8                           335 ns          348 ns      1878216\nBM_Updates/4/threads:16                          318 ns          342 ns      1556608\nBM_Updates/4/threads:32                          243 ns          331 ns      1952704\nBM_Updates/4/threads:64                          257 ns          355 ns      2050752\n    \u003c/pre\u003e\n  \u003c/dd\u003e\n\u003c/dl\u003e\n\n## Further objectives\n\n- Build a lock-free metrics collection library upon it.\n- Eventually provide bindings and/or similar implementations in other\n  languages: Rust, Haskell, Python, Go, etc.\n\n## Contributions\n\nPlease see [Code of Conduct](docs/code-of-conduct.md) and [Contributing](docs/contributing.md).\n\nIdeas for contributions:\n\n- Add bindings/implementations in other languages of your choice.\n- Improve documentation where needed. This project should ideally have also\n  some didactical value.\n- Popularize the project to be useful to others too. In particular there seems\n  to be just a copy-left (LGPLv2.1) user-space C++ RCU library\n  https://liburcu.org/, so having this one under a more permissive license could\n  be attractive for many projects.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppetr%2Flockfree-userspace-rcu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fppetr%2Flockfree-userspace-rcu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppetr%2Flockfree-userspace-rcu/lists"}