BASTA! TV: Ist Parallel Computing in .NET wirklich schon Daily Business?

by Marc Andre Zhou May 09, 2010 09:31

Mit .NET 4.0 haben Entwickler neue Möglichkeiten in Hinsicht auf die parallele Programmierung, die in Zukunft immer wichtiger werden wird. Bis vor kurzem konnte man sich darauf verlassen, dass die Geschwindigkeit von Programmen durch den Einsatz einer neuen CPU-Generation verbessert werden kann, doch dies gehört nun der Vergangenheit an. Jetzt hat man die Möglichkeit durch den Einsatz mehrerer CPU-Kerne in den PCs die Leistung zu steigern, doch um mehrere CPU-Kerne effektiv nutzen zu können, ist die parallele Programmierung von Nöten.

Auf der BASTA! Spring 2010 hat Katharina Friedrich, Redakteurin des dot.NET Magazins, die Möglichkeit genutzt, mit Marc André Zhou, Logica Deutschland GmbH & Co. KG, unter anderem über das Thema Parallel Computing zu sprechen.

Zum Interview >

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.NET | .NET Features | Buch | C# | Parallel FX | Threading

BASTA! TV: Parallel Computing

by Marc Andre Zhou February 27, 2010 11:46

Parallele Programmierung wird nicht nur für die .NET-Entwickler in Zukunft immer wichtiger werden, sondern allgemein an Bedeutung gewinnen. Steigerte man bisher die Leistungsfähigkeit von Anwendungen vor allem durch den Einsatz einer neuen Prozessorgeneration, so wird dies heute durch den gleichzeitigen Einsatz mehrerer CPU-Kerne gelöst. Grund genug, das Thema auf der BASTA! Spring 2009 genauer unter die Lupe zu nehmen. Marc André Zhou spricht in seiner Session über die Grundlagen der parallelen Programmierung in .NET 4.0 mit Parallel FX (Parallel Extension). Beginnend mit PLINQ über Tasks bis hin zu Future Objekt und Schleifen führt Zhou in die parallele Programmierung in .NET 4.0 ein. Zum Video ...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.NET | .NET Features | C# | Parallel FX | Parallel Task Library | PLINQ | Threading

Axum (vormals: MAESTRO) – Eine domänenspezifische Sprache für parallele Programmierung unter .NET

by Marc Andre Zhou December 02, 2009 04:01
Die kommende .NET-Framework-Version 4.0 beinhaltet wesentliche Verbesserungen, u. a. in Bezug auf parallele Verarbeitung. Die Task Parallel Library sowie die PLINQ-Erweiterung unterstützen den Entwickler, um einfach und effektiv parallele Verarbeitung in eigene Anwendungen zu integrieren. Die neuen API-Erweiterungen ermöglichen zwar die einfache Nutzung von Parallelität, dennoch verbleiben typische Probleme wie Race Conditions und Deadlocks, die der Entwickler beachten und lösen muss. Lesen Sie mehr in der aktuellen Ausgabe des dot.net Magazins.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.NET | .NET Features | Artikel | C# | Parallel FX | Parallel Task Library | PLINQ | Threading

Don't use volatile to synchronize your thread code ...

by Marc Andre Zhou June 19, 2009 08:34

EXAMPLE CODE IS ON THE WAY .... 

The C# Language contains the keyword volatile and I think this keyword is obsolete. Beside the fact that the using of volatile is often wrong and not necessary, the volatile keyword is often misinterpreted.

The volatile keyword gives often the wrong feeling of secure multithread code. Sometimes the volatile keyword is used to guarantee that a shared variable is not accessible from more than one thread during the same time.

BUT: The volatile keyword is not able to do this kind of service. The only way to protect a shared variable is to use a synchronization object (Monitor,Mutex) or the special static methods from the Interlocked class. 

Why? I’ve a simple example to demonstrate the effect of the volatile keyword and an example to solve the problem. At the end I’m going to explain the volatile keyword and the case, when it is necessary to use volatile.

The example below shows the wrong use of the volatile keyword:

Two threads are started and both threads are operating with the shared variable counter. The shared variable counter is incremented by both threads. If  everything is working fine, the result of the counter variable should be: ITERATION (const.) * Threads (in this case 2).

BUT: The counter variable is different from the expected value. Why? The keyword volatile is not helpful to guarantee thread-safety. In this case, the ++ Operation is not an atomicity operation. The volatile keyword guarantees that the “newest” value is reading from the memory and the value won’t be stored in a cache (L1, L2) but the value can be stored inside a CPU register. 

What happens exactly?
The ++ Operation contains more than one instruction to complete the operation. The following Intermediate Language Code (IL) shows the necessary instruction for the ++ Operation.

As you can see, the operation needs three steps to complete:

  • First: Load variable value (counter)
  • Second: Do the calculation
  • Third: Write back the result

On each operation it is possible that the thread will be interrupted. For example: A thread reads the variable counter and then the thread is interrupted, the variable value (counter) is stored inside the TIB (Thread Information Block). When the thread comes back to the processor (running again), the thread is using the stored value from the TIB. When a different thread has changed the value in the meantime, the old thread has no knowledge about this change. The re-activated thread is working with an old value. Writes the thread the value back to the memory, he overwrites the changes … Memory corrupted.   

The volatile keyword is not enough and not necessary on a x86 Architecure based CPU with Cache Coherency (Strong Memory Model)

The only way to solve the problem is to use a lock or the Interlocked class methods.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

.NET | C# | Threading

 
Marc Andre Zhou - China Signature