Previous: Signal Handling, Up: Preparation [Contents][Index]
The GPGME library is not entirely thread-safe, but it can still be used in a multi-threaded environment if some care is taken. If the following requirements are met, there should be no race conditions to worry about:
Support for other thread libraries is very easy to add. Please contact us if you have the need.
libgpgme-
followed by the name of the thread package you use.
For example, if you use GNU Pth, the right name is
libgpgme-pth
. Use the Automake macros or
gpgme-config
program for simplicity.
gpgme_check_version
must be called before any
other function in the library, because it initializes the thread
support subsystem in GPGME. To achieve this in
multi-threaded programs, you must synchronize the memory with respect
to other threads that also want to use GPGME. For this, it
is sufficient to call gpgme_check_version
before creating the
other threads using GPGME1.
gpgme_data_t
and gpgme_ctx_t
object must only be
accessed by one thread at a time. If multiple threads want to deal
with the same object, the caller has to make sure that operations on
that object are fully synchronized.
gpgme_wait
. If
multiple threads call this function, the caller must make sure that
all invocations are fully synchronized. It is safe to start
asynchronous operations while a thread is running in gpgme_wait.
gpgme_strerror
is not thread safe. You have to
use gpgme_strerror_r
instead.
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 other, more relaxed or more strict rules may apply.
Previous: Signal Handling, Up: Preparation [Contents][Index]