Server IP : 85.214.239.14 / Your IP : 3.22.27.41 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/self/root/proc/2/root/proc/3/cwd/proc/2/root/usr/share/doc/rrdtool/html/ |
Upload File : |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>rrdthreads</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rev="made" href="mailto:root@localhost" /> </head> <body> <h1 id="NAME">NAME</h1> <p>rrdthreads - Provisions for linking the RRD library to use in multi-threaded programs</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <p>Using librrd in multi-threaded programs requires some extra precautions, as the RRD library in its original form was not thread-safe at all. This document describes requirements and pitfalls on the way to use the multi-threaded version of librrd in your own programs. It also gives hints for future RRD development to keep the library thread-safe.</p> <p>Currently only some RRD operations are implemented in a thread-safe way. They all end in the usual "<code>_r</code>" suffix.</p> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p>In order to use librrd in multi-threaded programs you must:</p> <ul> <li><p>Link with <i>librrd_th</i> instead of <i>librrd</i> (use <code>-lrrd_th</code> when linking)</p> </li> <li><p>Use the "<code>_r</code>" functions instead of the normal API-functions</p> </li> <li><p>Do not use any at-style time specifications. Parsing of such time specifications is terribly non-thread-safe.</p> </li> <li><p>Never use non *<code>_r</code> functions unless it is explicitly documented that the function is tread-safe.</p> </li> <li><p>Every thread SHOULD call <code>rrd_get_context()</code> before its first call to any <code>librrd_th</code> 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.</p> </li> <li><p>Always call <code>rrd_error_clear()</code> before any call to the library. Otherwise the call might fail due to some earlier error.</p> </li> </ul> <h2 id="NOTES-FOR-RRD-CONTRIBUTORS">NOTES FOR RRD CONTRIBUTORS</h2> <p>Some precautions must be followed when developing RRD from now on:</p> <ul> <li><p>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:</p> <ul> <li><p>Direct calls to <code>strerror()</code> must be avoided: use <code>rrd_strerror()</code> instead, it provides a per-thread error message.</p> </li> <li><p>The <code>getpw*</code>, <code>getgr*</code>, <code>gethost*</code> function families (and some more <code>get*</code> functions) are not thread-safe: use the *<code>_r</code> variants</p> </li> <li><p>Time functions: <code>asctime</code>, <code>ctime</code>, <code>gmtime</code>, <code>localtime</code>: use *<code>_r</code> variants</p> </li> <li><p><code>strtok</code>: use <code>strtok_r</code></p> </li> <li><p><code>tmpnam</code>: use <code>tmpnam_r</code></p> </li> <li><p>Many others (lookup documentation)</p> </li> </ul> </li> <li><p>A header file named <i>rrd_is_thread_safe.h</i> is provided that works with the GNU C-preprocessor to "poison" some of the most common non-thread-safe functions using the <code>#pragma GCC poison</code> directive. Just include this header in source files you want to keep thread-safe.</p> </li> <li><p>Do not introduce global variables!</p> <p>If you really, really have to use a global variable you may add a new field to the <code>rrd_context</code> structure and modify <i>rrd_error.c</i>, <i>rrd_thread_safe.c</i> and <i>rrd_non_thread_safe.c</i></p> </li> <li><p>Do not use <code>getopt</code> or <code>getopt_long</code> in *<code>_r</code> (neither directly nor indirectly).</p> <p><code>getopt</code> uses global variables and behaves badly in a multi-threaded application when called concurrently. Instead provide a *_r function taking all options as function parameters. You may provide argc and **argv arguments for variable length argument lists. See <code>rrd_update_r</code> as an example.</p> </li> <li><p>Do not use the <code>rrd_parsetime</code> function!</p> <p>It uses lots of global variables. You may use it in functions not designed to be thread-safe, like in functions wrapping the <code>_r</code> version of some operation (e.g., <code>rrd_create</code>, but not in <code>rrd_create_r</code>)</p> </li> </ul> <h2 id="CURRENTLY-IMPLEMENTED-THREAD-SAFE-FUNCTIONS">CURRENTLY IMPLEMENTED THREAD SAFE FUNCTIONS</h2> <p>Currently there exist thread-safe variants of <code>rrd_update</code>, <code>rrd_create</code>, <code>rrd_dump</code>, <code>rrd_info</code>, <code>rrd_last</code>, and <code>rrd_fetch</code>.</p> <h1 id="AUTHOR">AUTHOR</h1> <p>Peter Stamfest <peter@stamfest.at></p> </body> </html>