..
All modern operating systems take years to be a model of multi-process management, assigning execution time and memory space to the various programs running simultaneously. In recent years, largely due to the pervasiveness of network communication, this concept has been extended to the individual software, dividing the same process multiple streams of control those threads. This new approach brings enormous changes to the structure of software, both in theory and in practice, as always happens, the modularity and expressiveness are paid in terms of increased software complexity.
The programming languages most recent, from Java, all offer native APIs for creating and managing threads; systems based on virtual machines such as Java and C # have the developer a level of abstraction consistent on this issue and all other must rely on the primitives of the operating system, often incurring problems of portability of code. In this context, the libraries are part of POSIX Threads (Pthreads) to allow C developers also a minimum guarantee of portability between different systems.
This article is aimed at anyone wishing to approach the topic of concurrent programming in low level languages. In this presentation assumes that the reader has already acquired a basic knowledge of C language will not be treated as basic topics such as, for example, memory management and data types.
As easily guessed from the name, the POSIX thread libraries are part of the set of POSIX (Portable Operating System Interface [for Unix]). Citing the definition "pthread [...] specifies a set of interfaces (functions, header files) for threaded programming process to single [...] Can Contain multiple threads, all of Which are executing the examination program [...] The Same share global memory (data and heap segments), but ITS Each thread has own stack. " This excerpt describes exactly what is involved in multi-programming in a POSIX threads:
Use the POSIX standard provides a high level of integration across all POSIX-compliant systems such as, for example, GNU / Linux, Mac OSX, BSD and even Windows (with some additions). Throughout this article we will refer to the use of GCC under GNU / Linux, of course, all considerations are carried forward to any other POSIX-like environment.
The pthread.h library provides everything you need for programming in a multi-threads, rather than make a mere listing of the primitives provided, we will present a practical example from time to time by discussing their differences.
So consider the following problem: the program must read from bank transfer several files of picking and / or deposit to be made to an account, then these files will have the following form:
+120 -550 +896 +5541 -85 ...To speed up different threads "cashier" each operate on a single file and updated concurrently customer's account, we performed all the operations in the output status of the account.
| |
AutoCAD (eBook)
Creation of architectural structures. At only 29 €. |
| |
Flash MX and ActionScript (Course)
Become a developer of Web sites from 29 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |