The GPGME library is mostly thread-safe, and can be used in a multi-threaded environment but there are some requirements for multi-threaded use:
gpgme_check_versionmust 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_versionbefore creating the other threads using GPGME1.
gpgme_ctx_tobject 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_strerroris not thread safe. You have to use
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.