1RRDTHREADS(1)                       rrdtool                      RRDTHREADS(1)
2
3
4

NAME

6       rrdthreads - Provisions for linking the RRD library to use in
7       multi-threaded programs
8

SYNOPSIS

10       Using librrd in multi-threaded programs requires some extra
11       precautions, as the RRD library in its original form was not thread-
12       safe at all. This document describes requirements and pitfalls on the
13       way to use the multi-threaded version of librrd in your own programs.
14       It also gives hints for future RRD development to keep the library
15       thread-safe.
16
17       Currently only some RRD operations are implemented in a thread-safe
18       way. They all end in the usual ""_r"" suffix.
19

DESCRIPTION

21       In order to use librrd in multi-threaded programs you must:
22
23       ·   Link with librrd_th instead of librrd (use "-lrrd_th" when linking)
24
25       ·   Use the ""_r"" functions instead of the normal API-functions
26
27       ·   Do not use any at-style time specifications. Parsing of such time
28           specifications is terribly non-thread-safe.
29
30       ·   Never use non *"_r" functions unless it is explicitly documented
31           that the function is tread-safe.
32
33       ·   Every thread SHOULD call "rrd_get_context()" before its first call
34           to any "librrd_th" function in order to set up thread specific
35           data. This is not strictly required, but it is the only way to test
36           if memory allocation can be done by this function. Otherwise the
37           program may die with a SIGSEGV in a low-memory situation.
38
39       ·   Always call "rrd_error_clear()" before any call to the library.
40           Otherwise the call might fail due to some earlier error.
41
42   NOTES FOR RRD CONTRIBUTORS
43       Some precautions must be followed when developing RRD from now on:
44
45       ·   Only use thread-safe functions in library code. Many often used
46           libc functions aren't thread-safe. Take care in the following
47           situations or when using the following library functions:
48
49           ·   Direct calls to "strerror()" must be avoided: use
50               "rrd_strerror()" instead, it provides a per-thread error
51               message.
52
53           ·   The "getpw*", "getgr*", "gethost*" function families (and some
54               more "get*" functions) are not thread-safe: use the *"_r"
55               variants
56
57           ·   Time functions: "asctime", "ctime", "gmtime", "localtime": use
58               *"_r" variants
59
60           ·   "strtok": use "strtok_r"
61
62           ·   "tmpnam": use "tmpnam_r"
63
64           ·   Many others (lookup documentation)
65
66       ·   A header file named rrd_is_thread_safe.h is provided that works
67           with the GNU C-preprocessor to "poison" some of the most common
68           non-thread-safe functions using the "#pragma GCC poison" directive.
69           Just include this header in source files you want to keep thread-
70           safe.
71
72       ·   Do not introduce global variables!
73
74           If you really, really have to use a global variable you may add a
75           new field to the "rrd_context" structure and modify rrd_error.c,
76           rrd_thread_safe.c and rrd_non_thread_safe.c
77
78       ·   Do not use "getopt" or "getopt_long" in *"_r" (neither directly nor
79           indirectly).
80
81           "getopt" uses global variables and behaves badly in a multi-
82           threaded application when called concurrently. Instead provide a
83           *_r function taking all options as function parameters. You may
84           provide argc and **argv arguments for variable length argument
85           lists. See "rrd_update_r" as an example.
86
87       ·   Do not use the "rrd_parsetime" function!
88
89           It uses lots of global variables. You may use it in functions not
90           designed to be thread-safe, like in functions wrapping the "_r"
91           version of some operation (e.g., "rrd_create", but not in
92           "rrd_create_r")
93
94   CURRENTLY IMPLEMENTED THREAD SAFE FUNCTIONS
95       Currently there exist thread-safe variants of "rrd_update",
96       "rrd_create", "rrd_dump", "rrd_info", "rrd_last", and "rrd_fetch".
97

AUTHOR

99       Peter Stamfest <peter@stamfest.at>
100
101
102
1031.7.0                             2018-01-05                     RRDTHREADS(1)
Impressum