Transactional memory for GCC 4.7.0
[Posted November 9, 2011 by corbet]
Following a last-minute
request, the
"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"
semantics.
A transaction looks something like this:
__transaction {
/* 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
transaction.
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.
(
Log in to post comments)