File: gpgme.info, Node: Multi-Threading, Prev: Signal Handling, Up: Preparation 2.8 Multi-Threading =================== 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: • The function ‘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 GPGME(1). • Any ‘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. • Only one thread at any time is allowed to call ‘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. • The function ‘gpgme_strerror’ is not thread safe. You have to use ‘gpgme_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 other, more relaxed or more strict rules may apply.