QuickStudy: Transactional Memory

Programmers are learning new ways to code for multicore computing systems.

With the increasing use of multicore CPUs in computers, programmers have to learn new techniques for parallel processing. One very promising approach is transactional memory.

The primary problem for programmers is that multiple programming threads that are executed simultaneously by different processors must often access the same memory or stored data. It is difficult to determine in advance which thread will write its results first. If one thread changes data in memory, that may invalidate another thread's processing.

Thus, the system needs to make sure that the correct write operations take place at the proper time, without interference, disruption or undue degradation of performance.

Definition:

Transactional memory is a programming approach for multiple CPUs designed to ensure that updates to shared memory are performed without interrupting or invalidating other code. Data changes are encapsulated in transactions and committed to memory only when safe -- that is, when it's clear that they will not interfere with other code. If two or more updates will change the same location, those transactions are rejected, no changes are made, and each transaction must try again until it succeeds.

To accomplish this, transactional memory runs code as "atomic blocks" inside a transaction, and all memory reads and writes are isolated until they are determined to be safe. Atomic here means that the code runs without interruption. When an atomic block completes, the system rechecks memory and looks for conflicts. Finding none, it executes the write operations, and these results become visible to the entire system.

If the system detects conflicts, however, it discards the transaction log and re-executes the block. When the contending threads are re-executed, they may proceed in a different order, thereby solving the conflict. While not exactly elegant, this solution seems to work well enough.

If an exception or error is somehow not handled inside the atomic block, all updates that block would make are automatically tossed away.

Where to find transactional memory systems

Sun Microsystems's forthcoming Rock family of multithreading, multicore Sparc microprocessors, expected to debut in 2009, will include hardware support for transactional memory. A programming approach Sun calls "hybrid transactional programming" will take advantage of the new hardware when available while hiding its limitations. For details about this, see "Hybrid Transactional Memory," by Peter Damron, Alexandra Fedorova, Yossi Lev, Victor Luchangco, Mark Moir and Daniel Nussbaum at research.sun.com.

And Microsoft Research is doing significant work on transactional memory, including adding support for existing languages such as C# and new languages such as Haskell and Atomos. For more information, see research.microsoft.com.

Join the newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.

Tags programming

More about MicrosoftRockSun Microsystems

Show Comments
[]