(gcrypt.info) Multi Threading

Info Catalog (gcrypt.info) Initializing the library (gcrypt.info) Preparation
 Multi Threading
 As mentioned earlier, the `Libgcrypt' library is thread-safe if you
 adhere to the following requirements:
    * If your application is multi-threaded, you must set the thread
      support callbacks with the `GCRYCTL_SET_THREAD_CBS' command
      *before* any other function in the library.
      This is easy enough if you are indeed writing an application using
      libgcrypt.  It is rather problematic if you are writing a library
      instead.  Here are some tips what to do if you are writing a
      If your library requires a certain thread package, just initialize
      gcrypt to use this thread package.  If your library supports
      multiple thread packages, but needs to be configured, you will
      have to implement a way to determine which thread package the
      application wants to use with your library anyway.  Then configure
      gcrypt to use this thread package.
      If your library is fully reentrant without any special support by a
      thread package, then you are lucky indeed.  Unfortunately, this
      does not relieve you from doing either of the two above, or use a
      third option.  The third option is to let the application
      initialize gcrypt for you.  Then you are not using gcrypt
      transparently, though.
      As if this was not difficult enough, a conflict may arise if two
      libraries try to initialize gcrypt independently of each others,
      and both such libraries are then linked into the same application.
      To make it a bit simpler for you, this will probably work, but
      only if both libraries have the same requirement for the thread
      package.  This is currently only supported for the non-threaded
      case, GNU Pth and pthread.  Support for more thread packages is
      easy to add, so contact is if you require it.
    * The function `gcry_check_version' must be called before any other
      function in the library, except the `GCRYCTL_SET_THREAD_CBS'
      command, because it initializes the thread support subsystem in
      Libgcrypt.  To achieve this in multi-threaded programs, you must
      synchronize the memory with respect to other threads that also
      want to use Libgcrypt.  For this, it is sufficient to call
      `gcry_check_version' before creating the other threads using
    * As with the function `gpg_strerror', `gcry_strerror' is not thread
      safe.  You have to use `gpg_strerror_r' instead.
    ---------- Footnotes ----------
    (1) At least this is true for POSIX threads, as `pthread_create' is
 a function that synchronizes memory with respects to other threads.
 There are many functions which have this property, a complete list can
 be found in POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in
 the definition of the term "Memory Synchronization".  For other thread
 packages, more relaxed or more strict rules may apply.
Info Catalog (gcrypt.info) Initializing the library (gcrypt.info) Preparation
automatically generated by info2html