RRDTHREADS(1)
π
RRDTHREADS β the rrdtool girlie's guide to threads
okay so bestie, this is the page about rrdthreads, which is all about linking the RRD library so you can use it in multi-threaded programs π§΅β¨
πΈ NAME πΈ
rrdthreads β the whole entire set of provisions for linking the RRD library so it behaves in multi-threaded programs π
β¨ SYNOPSIS β¨
So like, using librrd in multi-threaded programs needs some extra precautions, no cap. This doc describes the requirements and the pitfalls on the way to using librrd in your own programs. It also gives hints for future RRD development so the library stays thread-safe π₯
Big glow-up moment: since RRDtool 1.6, librrd is thread-safe, and no separate thread-specific library is needed. periodt π
π¦ DESCRIPTION π¦
In order to use librrd in multi-threaded programs you must:
- Link with
librrd(use-lrrdwhen linking) π - Use the
_rfunctions instead of the normal API-functions β¨ - Do not use any at-style time specifications. Parsing of such time specifications is terribly non-thread-safe. like, genuinely a mess π
- Never use non
_rfunctions unless it is explicitly documented that the function is thread-safe π - Every thread SHOULD call
rrd_get_context()before its first call to anylibrrdfunction in order to set up thread specific data. This is not strictly required, but it is the only way to test if memory allocation can be done by this function. Otherwise the program may die with aSIGSEGVin a low-memory situation π - Always call
rrd_clear_error()before any call to the library. Otherwise the call might fail due to some earlier error π
π NOTES FOR RRD CONTRIBUTORS π
Some precautions must be followed when developing RRD from now on, bestie β this is the main-character energy section π
- Only use thread-safe functions in library code. Many often used libc functions aren't thread-safe. Take care in the following situations or when using the following library functions:
- Direct calls to
strerror()must be avoided: userrd_strerror()instead, it provides a per-thread error message π«Ά - The
getpw*,getgr*,gethost*function families (and some moreget*functions) are not thread-safe: use the*_rvariants - Time functions:
asctime,ctime,gmtime,localtime: use*_rvariants β° strtok: usestrtok_rtmpnam: usetmpnam_r- Many others (lookup documentation) π
- Direct calls to
- A header file named
rrd_is_thread_safe.his provided that works with the GNU C-preprocessor to "poison" some of the most common non-thread-safe functions using the#pragma GCC poisondirective. Just include this header in source files you want to keep thread-safe π§ͺ - Do not introduce global variables! π«
- If you really, really have to use a global variable you may add a new field to the
rrd_contextstructure and modifyrrd_error.c,rrd_thread_safe.candrrd_non_thread_safe.c
- If you really, really have to use a global variable you may add a new field to the
- Do not use
getoptorgetopt_longin*_r(neither directly nor indirectly) πgetoptuses global variables and behaves badly in a multi-threaded application when called concurrently. Instead provide a*_rfunction taking all options as function parameters. You may provideargcand**argvarguments for variable length argument lists. Seerrd_update_ras an example π‘
- Do not use the
rrd_parsetimefunction! π€- It uses lots of global variables. You may use it in functions not designed to be thread-safe, like in functions wrapping the
_rversion of some operation (e.g.,rrd_create, but not inrrd_create_r)
- It uses lots of global variables. You may use it in functions not designed to be thread-safe, like in functions wrapping the
π CURRENTLY IMPLEMENTED THREAD SAFE FUNCTIONS π
Currently there exist thread-safe variants of rrd_update, rrd_create, rrd_dump, rrd_info, rrd_last, and rrd_fetch β iconic behaviour, honestly
π AUTHOR π
Peter Stamfest <peter@stamfest.at> π«Ά
k that's the whole page, bestie β go forth and thread safely πΈ
this cutie was brought to you by version 1.11.0, dated 2026-10-17 β mwah ππ
π¦ where this page comes from
- arch rolling: rrdtool 1.11.0-2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms