[cpp-threads] Fixing the thread type

Nick Maclaren nmm1 at cus.cam.ac.uk
Tue Nov 22 12:24:03 GMT 2005


Jason Merrill <jason at redhat.com> wrote:
> 
> >>We had a discussion about whether there should be a project
> >>to develop a C++ binding to POSIX. We think that
> >>we should investigate whether IEEE would be interested
> >>in doing this.
> > 
> > It's a crazy idea.  Until and unless POSIX comes up with a viable
> > threading model, that is binding to a mirage.
> 
> Viable or not, it exists, people use it with C++ code, and it ought to 
> be standardized.

Sigh.  That is precisely what they DON'T do.  They THINK that they
writing code to that specification, but what they are doing is writing
code to one interpretation of that specification.  Even if they have
deduced the undocumented behaviour of their implementation correctly,
their code is likely to fail on the next one they use.  They rarely
realise this and never document what their interpretation is :-(

The reason that this is not more visible is that almost nobody writes
POSIX threads codes that stresses the specification - for both good
and bad reasons.  The people that try get their fingers burnt, and
back off.  But what the former people don't realise is that they have
not AVOIDED the problems, but merely reduced the likelihood of seeing
a failure on their favoured implementation.

As I have posted before, the frequency of failure in (simple) race
conditions is proportional to the square of the frequency of the
incidence of potential conflicts, and the latter typically varies by
a factor of a thousand or more.  But not observing a failure doesn't
mean that the program is correct - as those of us that go spare with
non-repeatable failures in modern systems can witness.

The simple fact is that POSIX doesn't HAVE a threading model.  Its
wording on memory synchronisation is so loose as to be useless, and
it doesn't even MENTION the other, critical, common non-memory
interactions specified in POSIX - many of which are important to C++.
It is THAT that is needed to making binding useful, not mere syntactic
sugar.

> My personal interest in a C++ binding has to do with the interaction of 
> pthread_cancel and EH, which is currently badly broken on Linux because 
> of a deadlock between the libc and C++ people.  I have a dream that a 
> POSIX C++ binding could break that deadlock.

Sweet dreams, indeed :-)  When you wake up to the cruel world, please
tell me and we can start working on a proper model for POSIX thread
semantics!


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679



More information about the cpp-threads mailing list