Following a last-minute request
"transactional memory" GCC branch has been merged into the trunk for the
4.7.0 release. Transactional memory is specified in a
draft standard [PDF]
for C and C++; the idea is to provide a relatively
simple way for developers to execute code with atomic "all or nothing"
A transaction looks something like this:
/* Stuff done here is atomic */
Anything done within the __transaction block will either be
visible to other threads in its entirety or not at all. Most exits from a
transaction (return, goto, or break, for
example) will cause it to close normally. There is a
__transaction_cancel statement that can abort (and roll back) a
There are some constraints, naturally. If changes to a specific
variable are protected by a transaction in one place, all accesses to that
variable must be done within transactions. Transactions can only be rolled
back if they consist of exclusively "safe" statements; performing I/O is an
obvious way to lose transactional semantics. Exception handling gets more
complicated. All this leads to a certain
amount of complexity, with developers needing to mark functions as being
"safe," add Java-like declarations of exceptions that a function may raise,
and so on.
Details on the specific implementation are scarce; it appears that, in the
current patch set, transactions will be implemented using a global lock.
GCC developers debated for a bit over whether this code was ready for
merging or not. In the end, though, the possibility of being the first to
support an interesting new feature seemed to win out. Current plans are to
release 4.7.0 sometime around next April.
to post comments)