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

DESCRIPTION

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

AUTHOR

99       Peter Stamfest <peter@stamfest.at>
100
101
102
1031.2.27                            2008-02-17                     RRDTHREADS(1)
Impressum