Boost logo

Boost :

From: Miro Jurisic (macdev_at_[hidden])
Date: 2005-04-06 16:47:06

In article <004e01c53ac9$35901640$6601a8c0_at_pdimov>,
 "Peter Dimov" <pdimov_at_[hidden]> wrote:

> or something like that. Post-release. The current code is good (and risky)
> enough. :-)

My understanding from having spoken to several Apple engineers whom I consider
knowledgeable on this topic is that it's a very bad idea to write assembly code
to perform atomic operations on the PPC. There is a variety of CPU-specific
idiosyncracies that make it very difficult to write such code correctly. As you
might imagine, writing such code not quite correctly leads bugs that are very
hard to track down.

This recommendation is explicit in Apple's documentation at

"Do not use the PowerPC instructions Load Reserved (lwarx) and Store
Conditional (stwcx) to implement atomicity in your preemptively threaded
application. As described in DTS Technote 1137 Disabling Interrupts on the
Traditional Mac OS, these instructions are non-portable and are tricky to use
correctly across the full spectrum of PowerPC implementations."

For this reason, Apple supplies a number of atomic primitives in Mac OS 9 and
Mac OS X which perform a variety of modify-or-fail primitives; Apple takes it
upon themselves to make sure that their implementation is correct for the CPU
architectures that the OS supports, and I can guarantee you that Apple has more
time to develop and test these across a wide range of PPC hardware than we ever
will (or should try to).

I cannot understate how important it is that use the Apple APIs. They are
documented at
ards_drivers/PCI_BOOK.1a3.html>. Do not be concerned about the fact that this
documentation is for PCI drivers; the same APIs are available in userland with
#include <CoreServices/CoreServices.h>.


Boost list run by bdawes at, gregod at, cpdaniel at, john at