[cpp-threads] Floating-point state

Nick Maclaren nmm1 at cus.cam.ac.uk
Sat Aug 19 12:13:53 BST 2006


Well, while picking beans, I remembered one of the specific threading/
flag issues that I came across, and it is worth describing to explain
what the problem is.  The actual occurrence was POSIX signals/threads,
but the example applies equally well to IEEE 754 flags.

The clue here is that POSIX says nothing, zilch, nihilum about how
signals are synchronised between threads, and leaves all the details
of synchronisation to C, which doesn't include either signals or
threading in its model!  Signals exist, but are undefined behaviour.

Operation X is something that sets memory location A and flag P.

             Thread A                  Thread B
             --------                  --------
             Operation X
             ----------- synchronise ----------
                                       Read A and find it set
             ----------- synchronise ----------
             Find flag P unset

The point there was that the test of P was not synchronised in the
serial model with operation X, because there IS no synchronisation
of signals in C.  So it was completely undefined how the setting of A
and P were ordered - and there were and are no synchronisation
primitives for signals!

Now, IEEE 754 flags are a LITTLE better, but not much.  They are
associated with an operation, which must come before the storing of
the result.  Well, in reality, but none of the standards (C, C++ or
POSIX) say so, and certain optimisations can reverse that order.
So the issue remains, though it is less common in practice.

Anyone familiar with the Alpha architecture (and many others) will
know that it is allowed even at the hardware level.

Have I clarified the horror?

To repeat, this is why it is important to ask what the Decimal feature
is wanted FOR, so that we know whether reliable, precise support of
IEEE 754 flags is needed.  If not, and there are no other requirements
for them, this issue can be swept under the carpet by excluding them
from the threading model.  As is currently done for signals.


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