{"id":20978778,"url":"https://github.com/holmanb/userspace-rcu","last_synced_at":"2025-12-29T23:05:26.019Z","repository":{"id":111429003,"uuid":"483438705","full_name":"holmanb/userspace-rcu","owner":"holmanb","description":null,"archived":false,"fork":false,"pushed_at":"2022-04-19T23:50:24.000Z","size":3415,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"holmanb/leaks","last_synced_at":"2025-01-20T06:19:02.666Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/holmanb.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","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":"2022-04-19T23:18:34.000Z","updated_at":"2022-04-19T23:21:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"9a089841-43bd-4639-bb49-7c62c73376d9","html_url":"https://github.com/holmanb/userspace-rcu","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/holmanb%2Fuserspace-rcu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holmanb%2Fuserspace-rcu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holmanb%2Fuserspace-rcu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holmanb%2Fuserspace-rcu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/holmanb","download_url":"https://codeload.github.com/holmanb/userspace-rcu/tar.gz/refs/heads/holmanb/leaks","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243382783,"owners_count":20282007,"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-19T05:07:37.934Z","updated_at":"2025-12-29T23:05:26.012Z","avatar_url":"https://github.com/holmanb.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"Userspace RCU Implementation\n============================\n\nby Mathieu Desnoyers and Paul E. McKenney\n\n\nBuilding\n--------\n\n    ./bootstrap # skip if using tarball\n    ./configure\n    make\n    make install\n    ldconfig\n\nHints:\n\n  - Forcing 32-bit build:\n\n        CFLAGS=\"-m32 -g -O2\" ./configure\n\n  - Forcing 64-bit build:\n\n        CFLAGS=\"-m64 -g -O2\" ./configure\n\n  - Forcing a 32-bit build with 386 backward compatibility:\n\n        CFLAGS=\"-m32 -g -O2\" ./configure --host=i386-pc-linux-gnu\n\n  - Forcing a 32-bit build for Sparcv9 (typical for Sparc v9)\n\n        CFLAGS=\"-m32 -Wa,-Av9a -g -O2\" ./configure\n\n\nArchitectures supported\n-----------------------\n\nCurrently, the following architectures are supported:\n\n  - x86 (i386, i486, i586, i686)\n  - amd64 / x86_64\n  - PowerPC 32/64\n  - S390, S390x\n  - ARM 32/64\n  - MIPS\n  - NIOS2\n  - Alpha\n  - ia64\n  - Sparcv9 32/64\n  - Tilera\n  - hppa/PA-RISC\n  - m68k\n  - RISC-V\n\nTested on:\n\n  - Linux all architectures\n  - FreeBSD 8.2/8.3/9.0/9.1/10.0 i386/amd64\n  - Solaris 10/11 i386\n  - Cygwin i386/amd64\n  - MacOS amd64/arm64\n\nShould also work on:\n\n  - Android\n  - NetBSD 5\n  - OpenBSD\n  - Darwin\n\n(more testing needed before claiming support for these OS).\n\nLinux ARM depends on running a Linux kernel 2.6.15 or better, GCC 4.4 or\nbetter.\n\nThe C compiler used needs to support at least C99. The C++ compiler used\nneeds to support at least C++11.\n\nThe GCC compiler versions 3.3, 3.4, 4.0, 4.1, 4.2, 4.3, 4.4 and 4.5 are\nsupported, with the following exceptions:\n\n  - GCC 3.3 and 3.4 have a bug that prevents them from generating volatile\n    accesses to offsets in a TLS structure on 32-bit x86. These versions are\n    therefore not compatible with `liburcu` on x86 32-bit\n    (i386, i486, i586, i686).\n    The problem has been reported to the GCC community:\n    http://www.mail-archive.com/gcc-bugs@gcc.gnu.org/msg281255.html\n  - GCC 3.3 cannot match the \"xchg\" instruction on 32-bit x86 build.\n    See http://kerneltrap.org/node/7507\n  - Alpha, ia64 and ARM architectures depend on GCC 4.x with atomic builtins\n    support. For ARM this was introduced with GCC 4.4:\n    http://gcc.gnu.org/gcc-4.4/changes.html.\n  - Linux aarch64 depends on GCC 5.1 or better because prior versions\n    perform unsafe access to deallocated stack.\n\nClang version 3.0 (based on LLVM 3.0) is supported.\n\nGlibc \u003e= 2.4 should work but the older version we test against is\ncurrently 2.17.\n\nFor developers using the Git tree:\n\nThis source tree is based on the autotools suite from GNU to simplify\nportability. Here are some things you should have on your system in order to\ncompile the git repository tree :\n\n  - GNU autotools (automake \u003e=1.12, autoconf \u003e=2.69)\n    (make sure your system wide `automake` points to a recent version!)\n  - GNU Libtool \u003e=2.2\n    (for more information, go to http://www.gnu.org/software/autoconf/)\n\nIf you get the tree from the repository, you will need to use the `bootstrap`\nscript in the root of the tree. It calls all the GNU tools needed to prepare\nthe tree configuration.\n\nTest scripts provided in the `tests/` directory of the source tree depend\non `bash` and the `seq` program.\n\n\nAPI\n---\n\nSee the relevant API documentation files in `doc/`. The APIs provided by\nUserspace RCU are, by prefix:\n\n  - `rcu_`: Read-Copy Update (see [`doc/rcu-api.md`](doc/rcu-api.md))\n  - `cmm_`: Concurrent Memory Model\n  - `caa_`: Concurrent Architecture Abstraction\n  - `cds_`: Concurrent Data Structures\n    (see [`doc/cds-api.md`](doc/cds-api.md))\n  - `uatomic_`: Userspace Atomic\n    (see [`doc/uatomic-api.md`](doc/uatomic-api.md))\n\n\nQuick start guide\n-----------------\n\n### Usage of all urcu libraries:\n\n  - Define `_LGPL_SOURCE` (only) if your code is LGPL or GPL compatible\n    before including the `urcu.h` or `urcu-qsbr.h` header. If your application\n    is distributed under another license, function calls will be generated\n    instead of inlines, so your application can link with the library.\n  - Linking with one of the libraries below is always necessary even for\n    LGPL and GPL applications.\n  - Define `URCU_INLINE_SMALL_FUNCTIONS` before including Userspace RCU\n    headers if you want Userspace RCU to inline small functions (10\n    lines or less) into the application. It can be used by applications\n    distributed under any kind of license, and does *not* make the\n    application a derived work of Userspace RCU.\n\nThose small inlined functions are guaranteed to match the library\ncontent as long as the library major version is unchanged.\nTherefore, the application *must* be compiled with headers matching\nthe library major version number. Applications using\n`URCU_INLINE_SMALL_FUNCTIONS` may be unable to use debugging\nfeatures of Userspace RCU without being recompiled.\n\nThere are multiple flavors of liburcu available:\n\n  - `memb`,\n  - `qsbr`,\n  - `mb`,\n  - `signal`,\n  - `bp`.\n\nThe API members start with the prefix \"urcu_\u003cflavor\u003e_\", where\n\u003cflavor\u003e is the chosen flavor name.\n\n\n### Usage of `liburcu-memb`\n\n  1. `#include \u003curcu/urcu-memb.h\u003e`\n  2. Link the application with `-lurcu-memb`\n\nThis is the preferred version of the library, in terms of\ngrace-period detection speed, read-side speed and flexibility.\nDynamically detects kernel support for `sys_membarrier()`. Falls back\non `urcu-mb` scheme if support is not present, which has slower\nread-side. Use the --disable-sys-membarrier-fallback configure option\nto disable the fall back, thus requiring `sys_membarrier()` to be\navailable. This gives a small speedup when `sys_membarrier()` is\nsupported by the kernel, and aborts in the library constructor if not\nsupported.\n\n\n### Usage of `liburcu-qsbr`\n\n  1. `#include \u003curcu/urcu-qsbr.h\u003e`\n  2. Link with `-lurcu-qsbr`\n\nThe QSBR flavor of RCU needs to have each reader thread executing\n`rcu_quiescent_state()` periodically to progress. `rcu_thread_online()`\nand `rcu_thread_offline()` can be used to mark long periods for which\nthe threads are not active. It provides the fastest read-side at the\nexpense of more intrusiveness in the application code.\n\n\n### Usage of `liburcu-mb`\n\n  1. `#include \u003curcu/urcu-mb.h\u003e`\n  2. Link with `-lurcu-mb`\n\nThis version of the urcu library uses memory barriers on the writer\nand reader sides. This results in faster grace-period detection, but\nresults in slower reads.\n\n\n### Usage of `liburcu-signal`\n\n  1. `#include \u003curcu/urcu-signal.h\u003e`\n  2. Link the application with `-lurcu-signal`\n\nVersion of the library that requires a signal, typically `SIGUSR1`. Can\nbe overridden with `-DSIGRCU` by modifying `Makefile.build.inc`.\n\n\n### Usage of `liburcu-bp`\n\n  1. `#include \u003curcu/urcu-bp.h\u003e`\n  2. Link with `-lurcu-bp`\n\nThe BP library flavor stands for \"bulletproof\". It is specifically\ndesigned to help tracing library to hook on applications without\nrequiring to modify these applications. `urcu_bp_init()`, and\n`urcu_bp_unregister_thread()` all become nops, whereas calling\n`urcu_bp_register_thread()` becomes optional. The state is dealt with by\nthe library internally at the expense of read-side and write-side\nperformance.\n\n\n### Initialization\n\nEach thread that has reader critical sections (that uses\n`urcu_\u003cflavor\u003e_read_lock()`/`urcu_\u003cflavor\u003e_read_unlock()` must first\nregister to the URCU library. This is done by calling\n`urcu_\u003cflavor\u003e_register_thread()`. Unregistration must be performed\nbefore exiting the thread by using `urcu_\u003cflavor\u003e_unregister_thread()`.\n\n\n### Reading\n\nReader critical sections must be protected by locating them between\ncalls to `urcu_\u003cflavor\u003e_read_lock()` and `urcu_\u003cflavor\u003e_read_unlock()`.\nInside that lock, `rcu_dereference()` may be called to read an RCU\nprotected pointer.\n\n\n### Writing\n\n`rcu_assign_pointer()` and `rcu_xchg_pointer()` may be called anywhere.\nAfter, `urcu_\u003cflavor\u003e_synchronize_rcu()` must be called. When it\nreturns, the old values are not in usage anymore.\n\n\n### Usage of `liburcu-defer`\n\n  - Follow instructions for either `liburcu-memb`, `liburcu-qsbr`,\n    `liburcu-mb`, `liburcu-signal`, or `liburcu-bp` above.\n    The `liburcu-defer` functionality is pulled into each of\n    those library modules.\n  - Provides `urcu_\u003cflavor\u003e_defer_rcu()` primitive to enqueue delayed\n    callbacks. Queued callbacks are executed in batch periodically after\n    a grace period.  Do _not_ use `urcu_\u003cflavor\u003e_defer_rcu()` within a\n    read-side critical section, because it may call\n    `urcu_\u003cflavor\u003e_synchronize_rcu()` if the thread queue is full.  This\n    can lead to deadlock or worse.\n  - Requires that `urcu_\u003cflavor\u003e_defer_barrier()` must be called in\n    library destructor if a library queues callbacks and is expected to\n    be unloaded with `dlclose()`.\n\nIts API is currently experimental. It may change in future library releases.\n\n\n### Usage of `urcu-call-rcu`\n\n  - Follow instructions for either `liburcu-memb`, `liburcu-qsbr`,\n    `liburcu-mb`, `liburcu-signal`, or `liburcu-bp` above.\n    The `urcu-call-rcu` functionality is pulled into each of\n    those library modules.\n  - Provides the `urcu_\u003cflavor\u003e_call_rcu()` primitive to enqueue delayed\n    callbacks in a manner similar to `urcu_\u003cflavor\u003e_defer_rcu()`, but\n    without ever delaying for a grace period.  On the other hand,\n    `urcu_\u003cflavor\u003e_call_rcu()`'s best-case overhead is not quite as good\n    as that of `urcu_\u003cflavor\u003e_defer_rcu()`.\n  - Provides `urcu_\u003cflavor\u003e_call_rcu()` to allow asynchronous handling\n    of RCU grace periods.  A number of additional functions are provided\n    to manage the helper threads used by `urcu_\u003cflavor\u003e_call_rcu()`, but\n    reasonable defaults are used if these additional functions are not\n    invoked. See [`doc/rcu-api.md`](doc/rcu-api.md) in userspace-rcu\n    documentation for more details.\n\n\n### Being careful with signals\n\nThe `liburcu-signal` library uses signals internally. The signal handler is\nregistered with the `SA_RESTART` flag. However, these signals may cause\nsome non-restartable system calls to fail with `errno = EINTR`. Care\nshould be taken to restart system calls manually if they fail with this\nerror. A list of non-restartable system calls may be found in\n`signal(7)`.\n\nRead-side critical sections are allowed in a signal handler,\nexcept those setup with `sigaltstack(2)`, with `liburcu-memb` and\n`liburcu-mb`. Be careful, however, to disable these signals\nbetween thread creation and calls to `urcu_\u003cflavor\u003e_register_thread()`,\nbecause a signal handler nesting on an unregistered thread would not be\nallowed to call `urcu_\u003cflavor\u003e_read_lock()`.\n\nRead-side critical sections are _not_ allowed in a signal handler with\n`liburcu-qsbr`, unless signals are disabled explicitly around each\n`urcu_qsbr_quiescent_state()` calls, when threads are put offline and around\ncalls to `urcu_qsbr_synchronize_rcu()`. Even then, we do not recommend it.\n\n\n### Interaction with mutexes\n\nOne must be careful to do not cause deadlocks due to interaction of\n`urcu_\u003cflavor\u003e_synchronize_rcu()` and RCU read-side with mutexes. If\n`urcu_\u003cflavor\u003e_synchronize_rcu()` is called with a mutex held, this\nmutex (or any mutex which has this mutex in its dependency chain) should\nnot be acquired from within a RCU read-side critical section.\n\nThis is especially important to understand in the context of the\nQSBR flavor: a registered reader thread being \"online\" by\ndefault should be considered as within a RCU read-side critical\nsection unless explicitly put \"offline\". Therefore, if\n`urcu_qsbr_synchronize_rcu()` is called with a mutex held, this mutex,\nas well as any mutex which has this mutex in its dependency chain should\nonly be taken when the RCU reader thread is \"offline\" (this can be\nperformed by calling `urcu_qsbr_thread_offline()`).\n\n\n### Interaction with `fork()`\n\nSpecial care must be taken for applications performing `fork()` without\nany following `exec()`. This is caused by the fact that Linux only clones\nthe thread calling `fork()`, and thus never replicates any of the other\nparent thread into the child process. Most `liburcu` implementations\nrequire that all registrations (as reader, `defer_rcu` and `call_rcu`\nthreads) should be released before a `fork()` is performed, except for the\nrather common scenario where `fork()` is immediately followed by `exec()` in\nthe child process. The only implementation not subject to that rule is\n`liburcu-bp`, which is designed to handle `fork()` by calling\n`urcu_bp_before_fork`, `urcu_bp_after_fork_parent` and\n`urcu_bp_after_fork_child`.\n\nApplications that use `urcu_\u003cflavor\u003e_call_rcu()` and that `fork()`\nwithout doing an immediate `exec()` must take special action.  The\nparent must invoke `urcu_\u003cflavor\u003e_call_rcu_before_fork()` before the\n`fork()` and `urcu_\u003cflavor\u003e_call_rcu_after_fork_parent()` after the\n`fork()`. The child process must invoke\n`urcu_\u003cflavor\u003e_call_rcu_after_fork_child()`.  Even though these three\nAPIs are suitable for passing to `pthread_atfork()`, use of\n`pthread_atfork()` is **STRONGLY DISCOURAGED** for programs calling the\nglibc memory allocator (`malloc()`, `calloc()`, `free()`, ...) within\n`urcu_\u003cflavor\u003e_call_rcu` callbacks.  This is due to limitations in the\nway glibc memory allocator handles calls to the memory allocator from\nconcurrent threads while the `pthread_atfork()` handlers are executing.\n\nCombining e.g.:\n\n  - call to `free()` from callbacks executed within\n    `urcu_\u003cflavor\u003e_call_rcu` worker threads,\n  - executing `urcu_\u003cflavor\u003e_call_rcu` atfork handlers within the glibc\n    pthread atfork mechanism,\n\nwill sometimes trigger interesting process hangs. This usually\nhangs on a memory allocator lock within glibc.\n\n\n### Thread Local Storage (TLS)\n\nUserspace RCU can fall back on `pthread_getspecific()` to emulate\nTLS variables on systems where it is not available. This behavior\ncan be forced by specifying `--disable-compiler-tls` as configure\nargument.\n\n\n### Usage of `DEBUG_RCU` \u0026 `--enable-rcu-debug`\n\nBy default the library is configured with internal debugging\nself-checks disabled.\n\nFor always-on debugging self-checks:\n\t./configure --enable-rcu-debug\n\nFor fine grained enabling of debugging self-checks, build\nuserspace-rcu with DEBUG_RCU defined and compile dependent\napplications with DEBUG_RCU defined when necessary.\n\nWarning: Enabling this feature result in a performance penalty.\n\n\n### Usage of `DEBUG_YIELD`\n\n`DEBUG_YIELD` is used to add random delays in the code for testing\npurposes.\n\n\n### SMP support\n\nBy default the library is configured to use synchronization primitives\nadequate for SMP systems. On uniprocessor systems, support for SMP\nsystems can be disabled with:\n\n    ./configure --disable-smp-support\n\ntheoretically yielding slightly better performance.\n\n\n### Usage of `--enable-cds-lfht-iter-debug`\n\nBy default the library is configured with extra debugging checks for\nlock-free hash table iterator traversal disabled.\n\nBuilding liburcu with --enable-cds-lfht-iter-debug and rebuilding\napplication to match the ABI change allows finding cases where the hash\ntable iterator is re-purposed to be used on a different hash table while\nstill being used to iterate on a hash table.\n\nThis option alters the rculfhash ABI. Make sure to compile both library\nand application with matching configuration.\n\n\nMake targets\n------------\n\nIn addition to the usual `make check` target, Userspace RCU features\n`make regtest` and `make bench` targets:\n\n  - `make check`: short tests, meant to be run when rebuilding or\n    porting Userspace RCU.\n  - `make regtest`: long (many hours) test, meant to be run when\n    modifying Userspace RCU or porting it to a new architecture or\n    operating system.\n  - `make bench`: long (many hours) benchmarks.\n\n\nKnown issues\n------------\n\nThere is an application vs library compatibility issue between\napplications built using Userspace RCU 0.10 headers linked against\nUserspace RCU 0.11 or 0.12 shared objects. The problem occurs as\nfollows:\n\n  - An application executable is built with _LGPL_SOURCE defined, includes\n    any of the Userspace RCU 0.10 urcu flavor headers, and is built\n    without the -fpic compiler option.\n\n  - The Userspace RCU 0.10 library shared objects are updated to 0.11\n    or 0.12 without rebuilding the application.\n\n  - The application will hang, typically when RCU grace period\n    (synchronize_rcu) is invoked.\n\nSome possible work-arounds for this are:\n\n  - Rebuild the application against Userspace RCU 0.11+.\n\n  - Rebuild the application with -fpic.\n\n  - Upgrade Userspace RCU to 0.13+ without installing 0.11 nor 0.12.\n\n\nContacts\n--------\n\nYou can contact the maintainers on the following mailing list:\n`lttng-dev@lists.lttng.org`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholmanb%2Fuserspace-rcu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fholmanb%2Fuserspace-rcu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholmanb%2Fuserspace-rcu/lists"}