A site devoted mostly to everything related to Information Technology under the sun - among other things.

Friday, September 21, 2007

Concurrency Models

None of today's popular programming language is inherently parallelizable. No compiler for Java, C# and Visual Basic - much less C or C++ - will suddenly distribute the application's computations across multiple processors.

The current model of threading used in mainstream programming languages—the model of programmer-controlled threads and locks—is fundamentally broken since this is a model where callbacks are inherently unsafe.

There are other concurrency models, however, worth considering.

There is “message passing” (“shared nothing”) based on the principle that data stored inside objects should always be thread-local and that access from another thread should always be mediated by a method call that can be made responsible for synchronization. .NET’s ThreadLocalAttribute is using this model. The downside is that it requires an appreciable amount of “everything is an object” overhead on exactly the type of large data set most amenable to data-parallel performance benefits (for example, multimedia data).

The “software transactional memory” (STM) is basically optimistic concurrency for RAM. Essentially, the programmer becomes responsible not for controlling threads and locks but for identifying sequences that require atomicity. STM systems have an external component (some combination of library and compiler-generated code) that checks the validity of an atomic sequence and retries invalidated transactions. While such checking introduces some amount of overhead, it’s less than that of “shared nothing.” The performance of STM varies with the number of collisions and retries that are triggered.

There are a few C# libraries for STM, including one from Microsoft Research @ research.microsoft.com/research/downloads/Details/6cfc842d-1c16-4739-afaf-edb35f544384/Details.aspx

and another by Ralf Sudelbücher @

weblogs.asp.net/ralfw/archive/tags/Software+Transactional+Memory/default.aspx

Another model is the pure-functional programming (look at .Net's F# or Haskell) in which all state is passed through function parameters.

And the less ascetic model in which variables are immutable after their initial assignment. Such (along with message-passing) is the model of Erlang.

No comments:

About Me

My photo
I had been a senior software developer working for HP and GM. I am interested in intelligent and scientific computing. I am passionate about computers as enablers for human imagination. The contents of this site are not in any way, shape, or form endorsed, approved, or otherwise authorized by HP, its subsidiaries, or its officers and shareholders.

Blog Archive