[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gnupg-devel
Subject:    Re: gpgme and multithreading
From:       Marcus Brinkmann <Marcus.Brinkmann () ruhr-uni-bochum ! de>
Date:       2003-06-22 12:48:30
[Download RAW message or body]

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.

Thanks,
Marcus

-- 
`Rhubarb is no Egyptian god.' GNU      http://www.gnu.org    marcus@gnu.org
Marcus Brinkmann              The Hurd http://www.gnu.org/software/hurd/
Marcus.Brinkmann@ruhr-uni-bochum.de
http://www.marcus-brinkmann.de/

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic