Re: read-write locks

2017-01-05 Thread Bruno Haible
Torvald Riegel wrote: > whenever you have a bounded amount of parallel > work, you don't care what gets executed first. > ... > You control the incoming work. ... > > Look at your unit test, for example. Typically, the transactions would > be the result of some input operation, not spawned as fas

Re: bugs in test-lock

2017-01-05 Thread Bruno Haible
Torvald Riegel wrote: > > The problem here is: it's a unit test. If it fails, I don't want to search > > for bugs in the condition variable subsystem, semaphore subsystem, AND the > > lock subsystem. I want the test to rely essentially only on the lock > > subsystem. > > locks are the wrong mecha

Re: read-write locks

2017-01-05 Thread Paul Eggert
On 01/05/2017 12:47 PM, Torvald Riegel wrote: > If gnulib really wants to make concurrency simpler, than it should look > at higher-level abstractions first. Especially parallelism. But maybe > it should then just wait for what C++ specifies, or contribute to that I'm afraid this overestimates t

Re: read-write locks

2017-01-05 Thread Kamil Dudka
On Thursday, January 05, 2017 21:13:07 Bruno Haible wrote: > Torvald Riegel wrote: > > IMO, users of reader-writer locks should treat them as a > > mutual-exclusion mechanism. That is, a mechanism that just ensures that > > two critical sections will not execute concurrently (except if both are >

Re: bugs in gnulib thread modules

2017-01-05 Thread Bruno Haible
Torvald Riegel wrote: > > Can you give line numbers, please? lib/glthread/lock.c and > > lib/glthread/cond.c > > are large files. If you have found bugs there, *of course* I want to have > > them fixed. > > I can understand both points. However, I'd suggest that you first try > to find them (or

Re: bugs in test-lock

2017-01-05 Thread Torvald Riegel
On Thu, 2017-01-05 at 19:42 +0100, Bruno Haible wrote: > Torvald Riegel wrote [in private email, should have CCed bug-gnulib]: > > [about the use of a lock in 'struct atomic_int' in test-lock.c:] > > > > The delivered code, with a lock, is correct, however, right? > > > > Not quite, unfortunatel

Re: read-write locks

2017-01-05 Thread Torvald Riegel
On Thu, 2017-01-05 at 21:13 +0100, Bruno Haible wrote: > Torvald Riegel wrote: > > IMO, users of reader-writer locks should treat them as a > > mutual-exclusion mechanism. That is, a mechanism that just ensures that > > two critical sections will not execute concurrently (except if both are > > re

Re: bugs in gnulib thread modules

2017-01-05 Thread Torvald Riegel
On Thu, 2017-01-05 at 20:15 +0100, Bruno Haible wrote: > Torvald Riegel wrote: > > I found two bugs just by briefly scanning through the current > > lib/glthread/lock.c. As a hint, I'll just mention double-checked > > locking and order of destruction. And skipping destruction is of course > > not

Re: C11 atomics

2017-01-05 Thread Torvald Riegel
On Thu, 2017-01-05 at 20:30 +0100, Bruno Haible wrote: > Torvald Riegel wrote: > > IMHO, gnulib synchronization primitives should simply move towards the > > semantics chosen by C++11 and more recent (if you dislike C++ for some > > reason, just use the C++ semantics applied to C11; C is lacking be

Re: read-write locks

2017-01-05 Thread Bruno Haible
Torvald Riegel wrote: > IMO, users of reader-writer locks should treat them as a > mutual-exclusion mechanism. That is, a mechanism that just ensures that > two critical sections will not execute concurrently (except if both are > readers, of course), so at the same time. It is also important to

Re: C11 atomics

2017-01-05 Thread Bruno Haible
Torvald Riegel wrote: > IMHO, gnulib synchronization primitives should simply move towards the > semantics chosen by C++11 and more recent (if you dislike C++ for some > reason, just use the C++ semantics applied to C11; C is lacking behind > in terms of preciseness of the specification). > > Of c

Re: bugs in gnulib thread modules

2017-01-05 Thread Bruno Haible
Torvald Riegel wrote: > I found two bugs just by briefly scanning through the current > lib/glthread/lock.c. As a hint, I'll just mention double-checked > locking and order of destruction. And skipping destruction is of course > not correct in the general case either (unless I'm misreading > lib/

Re: Test-lock hang (not 100% reproducible) on GNU/Linux

2017-01-05 Thread Bruno Haible
Pavel Raiskup wrote: > Thanks. Minor report is that gl_thread_join() is not handled properly for > joined thread statuses. > > This leads to situation that Koji build system tries to gently terminate > the build first (after two days) ... which (sometimes?) leads to successful > 'test-lock' run i

Re: bugs in test-lock

2017-01-05 Thread Bruno Haible
Torvald Riegel wrote [in private email, should have CCed bug-gnulib]: [about the use of a lock in 'struct atomic_int' in test-lock.c:] > > The delivered code, with a lock, is correct, however, right? > > Not quite, unfortunately, because locks do not make any guarantees > regarding fairness. Th

Re: Test-lock hang (not 100% reproducible) on GNU/Linux

2017-01-05 Thread Torvald Riegel
IMO, users of reader-writer locks should treat them as a mutual-exclusion mechanism. That is, a mechanism that just ensures that two critical sections will not execute concurrently (except if both are readers, of course), so at the same time. It is also important to understand what this does not

Re: Test-lock hang (not 100% reproducible) on GNU/Linux

2017-01-05 Thread Pavel Raiskup
Thanks. Minor report is that gl_thread_join() is not handled properly for joined thread statuses. This leads to situation that Koji build system tries to gently terminate the build first (after two days) ... which (sometimes?) leads to successful 'test-lock' run in the end and the build succeeds

Re: Test-lock hang (not 100% reproducible) on GNU/Linux

2017-01-05 Thread Bruno Haible
Pavel Raiskup wrote: > I still see infinite hang on ppc64le (sometimes), as discussed in [1]. It > looks like starvation of writers in test_rwlock(). > > Could we set PTHREAD_RWLOCK_PREFER_WRITER_NP (in test-lock.c) to avoid > those issues? Here's what I'm pushing. You were right with your intu

thread: fix pth port

2017-01-05 Thread Bruno Haible
When a gnulib testdir is configured with --enable-threads=pth --with-libpth-prefix=... the test test-thread_create crashes. The reason is that most Pth functions crash (and pth_self() returns the value NULL) if pth_init() has not been called. This patch fixes the gnulib 'thread' module according