forked from oetiker/rrdtool-1.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
THREADS
42 lines (31 loc) · 1.66 KB
/
THREADS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Every thread SHOULD call rrd_get_context() before the first call to
any librrd function 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 a SIGSEGV in a low-memory situation.
IMPORTANT NOTE FOR RRD CONTRIBUTORS:
Some precautions must be followed when developing rrd from now on:
* Only use thread-safe functions in library code. Many often used libc
functions aren't thread-safe. Take care if you want to use any of
the following functions:
+ direct strerror calls must be avoided: use rrd_strerror instead,
it provides a per-thread error message
+ the getpw*, getgr*, gethost* function families (and some more get*
functions): use the *_r variants
+ Time functions: asctime, ctime, gmtime, localtime: use *_r variants
+ strtok: use strtok_r
+ tmpnam: use tmpnam_r
+ many other (lookup documentation)
As an aide(?) a header file named "rrd_is_thread_safe.h" is provided
that works with the GNU C-preprocessor to "poison" some of the most
common non-thread-safe functions using the "#pragma GCC poison"
directive. 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_context structure and modify rrd_error.c and
rrd_thread_safe.c
* Do not use the parsetime function!
If you do make sure to lock your use.
WIN32 Platform Note (added 04/01/03):
Both rrdtool.vcproj (MSVC++ 7.0) and rrd.dsw (MSVC++ 6.0) are configured to compile with rrd_thread_safe_nt.c.