..


Sponsored Links

Concurrent programming in C + +

Article written by Stefano Cancedda
Page 1 of 6

Sequence programming offers the guarantee that the instructions are always executed in order, with no variations. The resulting behavior is deterministic: inserting the same inputs, output is obtained the same result.
For each program running the operating system creates a process which gives a protected memory space. This provides the possibility that independent processes are operating simultaneously without errors.

Different (and more advanced) is the concurrent programming. Before the siege is to be introduced and how it works, in my opinion, a particular type of object called a kernel thread.

As objects Kernel threads are managed by the operating system, and have two fundamental features:

  • Each thread has a private data structure, which stores its own stack, exception information, the next instruction to be executed;
  • Each thread shares with the whole process a common memory area.
The use of threads has several advantages in terms of execution. In particular, we fully exploit the performance of multi-core CPUs, which are currently the dominant technology in the market for personal computers. It is unthinkable that a certain complexity of modern applications are designed in a sequential manner, thus could take advantage of the time, only one of the core that the machine provides.

As another advantage, it can be seen as two different processes running the same code, perhaps with different parameters, are less efficient than two threads that can directly exploit the shared memory. In a system that does not support threads, if you want to run several times the same program, you must create more jobs based on the same program. This technique works but is wasteful of resources and is slower.

Thirdly, the threads have the advantage if they are called the I / O blockers: instead of waiting for the event triggered by the user stopping the execution of the algorithm, you can start a new thread and prevent unnecessary downtime that worsens the overall performance.

In contrast to the concurrent programming needs the support of synchronization constructs, which are fundamental to avoid random accesses to shared memory cause errors in output. Also exposes the programmer to a series of errors often poorly nourished because of the unpredictable behavior of deterministic program.

Besides this, the synchronization constructs have a cost, both in terms of machine time needed to execute their code in a loss of performance caused mainly by expectations generated by these constructs in order to ensure fairness in carrying out competitor.

The main objects that allow the management of competition are anticipated below and described in detail in the following paragraphs:

  • Volatile elements
  • Interlocked Functions
  • Traffic lights
  • Critical sections
  • Events
  • Timer
  • Mutex
Each of these elements fit in a natural way to solve a specific class of simple problems. For more complex problems simply combine these objects together to get a correct result and satisfactory passage of the resolution of problems that require the use of one of the earliest and the problems that are defined as above is a complex highly critical. The combination of synchronization objects can be complicated, at best, because you can not get a sufficiently high performance in a worst case, because you can not easily find the solution that ensures the correctness of the result. Not least the worst case: there is a fatal bug and did not immediately identify. This juncture is very frequent, both because of the sensitivity of the issues we will discuss, is the fact that debugging is always problematic in concurrent environment, the flows are in fact deterministic execution, each execution of the program, the order the processor performs the operations is always different.

In the same category ...
E-Learning
E-commerce with ASP (Ebook) E-commerce with ASP (Ebook)
ECommerce and Shopping Cart with ASP. Only 35 €.
Flash MX (Advanced) Flash MX (Advanced)
Become a designer of Web sites from 29 €.
MS Access (Advanced) MS Access (Advanced)
Learn how to create and manage databases quickly and easily. Starting from 29 €.
Sponsored Links