[PATCH 2/5] dirmngr: hkp: avoid race condition when some hosts die

Werner Koch wk at gnupg.org
Tue Nov 1 17:49:16 CET 2016


On Tue,  1 Nov 2016 16:13, dkg at fifthhorseman.net said:

> Sorry, i wasn't aware that the only place where a thread could execute
> concurrently was in a call into the kernel.  Will npth never provide
> concurrent execution on any multiprocessor architecture?

That is the whole point of using nPth or the older Pth.  You can
implement most algorithms without thinking about multithreading as long
as you avoid blocking system calls.  nPth is a wrapper around all
blocking system calls which is best illustrated by looking at one of
these calls (modified for readability):

  ssize_t
  npth_read(int fd, void *buf, size_t nbytes)
  {
    ssize_t res;
  
    sem_post (sceptre);  /* This is the core of enter_pth () */
    res = read(fd, buf, nbytes);
    sem_wait (sceptre);  /* This is the core of leave_pth () */
    return res;
  }

The semaphore SCEPTRE has been initialized to 1 (by npth_init at the
start of the program).  Due to the sem_post other threads can continue
to run so that the read() can block but other blocking system calls will
continue to run.  The sem_wait then makes sure that outside of npth_read
only one thread is running.

For special purposes the user may control the blocking on his own by
using npth_enter and npth_leave and thus create threads which run
independent from the npth created threads.  This is for example required
to work with libraries which are not nPth aware (e.g. LDAP).

> I also wasn't aware that xtrymalloc() was guaranteed to never call
> brk().

It doesn't matter because brk is not a blocking call and not wrapped by
nPth.  nPth actually requires the expclit use of nPth versions of the
blocking calls.

> and maintainability of the code, i'm happy to rebase this series without
> it -- the only difference, i suppose, is that i'll have to remove the

I have only picked this patch because I noticed the term "race" in the
subject.

In general I would like to postpone all these patches because they do
not add required features or fixes.  We have a whole bunch of other
topics to address in the next weeks and any other new code will only
delay a release even more.


Shalom-Salam,

   Werner


p.s. 
Please remember to capitalize the first word of a sentence and the
word after a colon in the Changelog entries.

-- 
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: </pipermail/attachments/20161101/40d65773/attachment.sig>


More information about the Gnupg-devel mailing list