Extreme C
eBook - ePub

Extreme C

Taking you to the limit in Concurrency, OOP, and the most advanced capabilities of C

Kamran Amini

Partager le livre
  1. 822 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Extreme C

Taking you to the limit in Concurrency, OOP, and the most advanced capabilities of C

Kamran Amini

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

Push the limits of what C - and you - can do, with this high-intensity guide to the most advanced capabilities of C

Key Features

  • Make the most of C's low-level control, flexibility, and high performance
  • A comprehensive guide to C's most powerful and challenging features
  • A thought-provoking guide packed with hands-on exercises and examples

Book Description

There's a lot more to C than knowing the language syntax. The industry looks for developers with a rigorous, scientific understanding of the principles and practices. Extreme C will teach you to use C's advanced low-level power to write effective, efficient systems. This intensive, practical guide will help you become an expert C programmer.

Building on your existing C knowledge, you will master preprocessor directives, macros, conditional compilation, pointers, and much more. You will gain new insight into algorithm design, functions, and structures. You will discover how C helps you squeeze maximum performance out of critical, resource-constrained applications.

C still plays a critical role in 21st-century programming, remaining the core language for precision engineering, aviations, space research, and more. This book shows how C works with Unix, how to implement OO principles in C, and fully covers multi-processing.

In Extreme C, Amini encourages you to think, question, apply, and experiment for yourself. The book is essential for anybody who wants to take their C to the next level.

What you will learn

  • Build advanced C knowledge on strong foundations, rooted in first principles
  • Understand memory structures and compilation pipeline and how they work, and how to make most out of them
  • Apply object-oriented design principles to your procedural C code
  • Write low-level code that's close to the hardware and squeezes maximum performance out of a computer system
  • Master concurrency, multithreading, multi-processing, and integration with other languages
  • Unit Testing and debugging, build systems, and inter-process communication for C programming

Who this book is for

Extreme C is for C programmers who want to dig deep into the language and its capabilities. It will help you make the most of the low-level control C gives you.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Extreme C est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Extreme C par Kamran Amini en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Programming in C. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2019
ISBN
9781789341355
Édition
1

Chapter 18

Process Synchronization

This chapter continues our discussion in the previous chapter, Process Execution, and our main focus will be on process synchronization. Control mechanisms in multi-process programs are different from the control techniques we met in multi-threaded programs. It is not just the memory which differs; there are other factors that you cannot find in a multi-threaded program, and they exist in a multi-process environment.
Despite threads that are bound to a process, processes can live freely on any machine, with any operating system, located anywhere within a network as big as the internet. As you might imagine, things become complicated. It will not be easy to synchronize a number of processes in such a distributed system.
This chapter is dedicated to process synchronization happening in just one machine. In other words, it mainly talks about single-host synchronization and the techniques around it. We discuss briefly the process synchronization in distributed systems, but we won't go into extensive detail.
This chapter covers the following topics:
  • Firstly, we describe multi-process software where all processes are being run on the same machine. We introduce the techniques that are available in single-host environments. We use the knowledge from the previous chapter in order to give some examples that demonstrate these techniques.
  • In our first attempt to synchronize a number of processes, we use named POSIX semaphores. We explain how they should be used and then we give an example that resolves a race condition issue we encountered in the previous chapters.
  • After that, we talk about named POSIX mutexes and we show how we can use shared memory regions to have named mutexes up and working. As an example, we solve the same race condition resolved by semaphores, this time using named mutexes.
  • As the last technique to synchronize a number of processes, we discuss named POSIX condition variables. Like named mutexes, they need to be put in a shared memory region to become accessible to a number of processes. We give a thorough example regarding this technique which shows how named POSIX condition variables can be used to synchronize a multi-process system.
  • As our final discussion in this chapter, we briefly talk about the multi-process systems which have their own processes distributed around a network. We discuss their features and the problematic differences that they have in comparison to a single-host multi-process system.
Let us start the chapter with talking a bit more about single-host concurrency control and what techniques are available as part of it.

Single-host concurrency control

It is pretty common to be in situations where there are a number of processes running on a single machine that, at the same time, need to have simultaneous access to a shared resource. Since all of the processes are running within the same operating system, they have access to all the facilities which their operating system provides.
In this section, we show how to use some of these facilities to create a control mechanism that synchronizes the processes. Shared memory plays a key role in most of these control mechanisms; therefore, we heavily rely on what we explained about shared memory in the previous chapter.
The following is a list of POSIX-provided control mechanisms that can be employed while all processes are running on the same POSIX-compliant machine:
  • Named POSIX semaphores: The same POSIX semaphores that we explained in Chapter 16, Thread Synchronization, but with one difference: they have a name now and can be used globally throughout the system. In other words, they are not anonymous or private semaphores anymore.
  • Named mutexes: Again, the same POSIX mutexes with the same properties which were explained in Chapter 16, Thread Synchronization, but now named and can be used throughout the system. These mutexes should be placed inside a shared memory in order to be available to multiple processes.
  • Named condition variables: The same POSIX condition variables which we explained in Chapter 16, Thread Synchronization, but like mutexes, they should be placed inside a shared memory object in order to be available to a number of processes.
In the upcoming sections, we discuss all the above techniques and give examples to demonstrate how they work. In the following section, we are going to discuss named POSIX semaphores.

Named POSIX semaphores

As you saw in Chapter 16, Thread Synchronization, semaphores are the main tool to synchronize a number of concurrent tasks. We saw them in multi-threaded programs and saw how they help to overcome the concurrency issues.
In this section, we are going to show how they can be used among some processes. Example 18.1 shows how to use a POSIX semaphore to solve the data races we encountered in examples 17.6 and 17.7 given in the previous chapter, Process Execution. The example is remarkably similar to example 17.6, and it again uses a shared memory region for storing the ...

Table des matiĂšres