{
    "content": [
        {
            "type": "text",
            "text": "# rrdthreads (man)\n\n## NAME\n\nrrdthreads - Provisions for linking the RRD library to use in multi-threaded programs\n\n## SYNOPSIS\n\nUsing librrd in multi-threaded programs requires some extra precautions, as the RRD library\nin its original form was not thread-safe at all. This document describes requirements and\npitfalls on the way to use the multi-threaded version of librrd in your own programs. It also\ngives hints for future RRD development to keep the library thread-safe.\nCurrently only some RRD operations are implemented in a thread-safe way. They all end in the\nusual \"\"r\"\" suffix.\n\n## DESCRIPTION\n\nIn order to use librrd in multi-threaded programs you must:\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **AUTHOR**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "rrdthreads",
        "section": "",
        "mode": "man",
        "summary": "rrdthreads - Provisions for linking the RRD library to use in multi-threaded programs",
        "synopsis": "Using librrd in multi-threaded programs requires some extra precautions, as the RRD library\nin its original form was not thread-safe at all. This document describes requirements and\npitfalls on the way to use the multi-threaded version of librrd in your own programs. It also\ngives hints for future RRD development to keep the library thread-safe.\nCurrently only some RRD operations are implemented in a thread-safe way. They all end in the\nusual \"\"r\"\" suffix.",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 69,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "rrdthreads - Provisions for linking the RRD library to use in multi-threaded programs\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "Using librrd in multi-threaded programs requires some extra precautions, as the RRD library\nin its original form was not thread-safe at all. This document describes requirements and\npitfalls on the way to use the multi-threaded version of librrd in your own programs. It also\ngives hints for future RRD development to keep the library thread-safe.\n\nCurrently only some RRD operations are implemented in a thread-safe way. They all end in the\nusual \"\"r\"\" suffix.\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "In order to use librrd in multi-threaded programs you must:\n\n•   Link with librrdth instead of librrd (use \"-lrrdth\" when linking)\n\n•   Use the \"\"r\"\" functions instead of the normal API-functions\n\n•   Do not use any at-style time specifications. Parsing of such time specifications is\nterribly non-thread-safe.\n\n•   Never use non *\"r\" functions unless it is explicitly documented that the function is\ntread-safe.\n\n•   Every thread SHOULD call \"rrdgetcontext()\" before its first call to any \"librrdth\"\nfunction in order to set up thread specific data. This is not strictly required, but it\nis the only way to test if memory allocation can be done by this function. Otherwise the\nprogram may die with a SIGSEGV in a low-memory situation.\n\n•   Always call \"rrderrorclear()\" before any call to the library. Otherwise the call might\nfail due to some earlier error.\n\nNOTES FOR RRD CONTRIBUTORS\nSome precautions must be followed when developing RRD from now on:\n\n•   Only use thread-safe functions in library code. Many often used libc functions aren't\nthread-safe. Take care in the following situations or when using the following library\nfunctions:\n\n•   Direct calls to \"strerror()\" must be avoided: use \"rrdstrerror()\" instead, it\nprovides a per-thread error message.\n\n•   The \"getpw*\", \"getgr*\", \"gethost*\" function families (and some more \"get*\" functions)\nare not thread-safe: use the *\"r\" variants\n\n•   Time functions: \"asctime\", \"ctime\", \"gmtime\", \"localtime\": use *\"r\" variants\n\n•   \"strtok\": use \"strtokr\"\n\n•   \"tmpnam\": use \"tmpnamr\"\n\n•   Many others (lookup documentation)\n\n•   A header file named rrdisthreadsafe.h is provided that works with the GNU\nC-preprocessor to \"poison\" some of the most common non-thread-safe functions using the\n\"#pragma GCC poison\" directive. Just include this header in source files you want to keep\nthread-safe.\n\n•   Do not introduce global variables!\n\nIf you really, really have to use a global variable you may add a new field to the\n\"rrdcontext\" structure and modify rrderror.c, rrdthreadsafe.c and\nrrdnonthreadsafe.c\n\n•   Do not use \"getopt\" or \"getoptlong\" in *\"r\" (neither directly nor indirectly).\n\n\"getopt\" uses global variables and behaves badly in a multi-threaded application when\ncalled concurrently. Instead provide a *r function taking all options as function\nparameters. You may provide argc and argv arguments for variable length argument lists.\nSee \"rrdupdater\" as an example.\n\n•   Do not use the \"rrdparsetime\" function!\n\nIt uses lots of global variables. You may use it in functions not designed to be thread-\nsafe, like in functions wrapping the \"r\" version of some operation (e.g., \"rrdcreate\",\nbut not in \"rrdcreater\")\n\nCURRENTLY IMPLEMENTED THREAD SAFE FUNCTIONS\nCurrently there exist thread-safe variants of \"rrdupdate\", \"rrdcreate\", \"rrddump\",\n\"rrdinfo\", \"rrdlast\", and \"rrdfetch\".\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Peter Stamfest <peter@stamfest.at>\n\n\n\n1.7.2                                        2022-03-17                                RRDTHREADS(1)",
                "subsections": []
            }
        }
    }
}