gpgme and multithreading

Marcus Brinkmann Marcus.Brinkmann at
Sun Jun 22 15:47:01 CEST 2003

On Sun, Jun 22, 2003 at 11:25:45AM +0200, Stéphane Corthésy wrote:
> I'd like to use the asynchronous calls of gpgme, but I wouldn't like to 
> have to implement the IO callbacks; not so easy on OSX, at first sight. 
> I thought about that other strategy, and wonder if that would be safe.
> - All calls made to contexts/data/etc are done in the main thread
> - in a secondary thread, I invoke gpgme_wait(NULL, statusPtr, 1) - 
> blocking call; when call returns, I pass information in the main thread 
> to handle results. In the secondary thread, IF there are some async 
> calls that have been made on contexts, then I invoke again 
> gpgme_wait(), else thread is blocked (semaphore) until an async call is 
> done.
> Would this be safe with gpgme?

That should be perfectly fine and is exactly how the gpgme_wait (NULL,...)
variant is intended to be used.  I think you will be the first one to
actually use it, so there might be bugs.  If you find any, I am very
interested in hearing about them.

In particular, there should be no problem to start asynchronous operations
while you block in gpgme_wait.  Any local lock you use to protect the
metadata on your side should be released while blocking in gpgme_wait, so
you can take them when starting more operations.  After gpgme_wait returns,
you can take the local lock to lookup the metadata for the result
notification to the main thread (however you are doing it).  This is pretty
vanilla stuff in multithreaded server programs with worker threads.


`Rhubarb is no Egyptian god.' GNU    marcus at
Marcus Brinkmann              The Hurd
Marcus.Brinkmann at

More information about the Gnupg-devel mailing list