Book Image

Extreme C

By : Kamran Amini
5 (1)
Book Image

Extreme C

5 (1)
By: Kamran Amini

Overview of this book

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.
Table of Contents (23 chapters)

Named condition variables

As we explained before, similar to named POSIX mutexes, we need to allocate a POSIX condition variable from a shared memory region in order to use it in a multi-processing system. The following example, example 18.4, shows how to do so in order to make a number of processes count in a specific order. As you know from Chapter 16, Thread Synchronization, every condition variable should be used together with a companion mutex object which protects it. Therefore, we will have three shared memory regions in example 18.4; one for the shared counter, one for the shared named condition variable, and one for the shared named mutex protecting the shared condition variable.

Note that instead of having three different shared memories, we could also use a single shared memory. This is possible by defining a structure that encompasses all the required objects. In this example, we are not going to take this approach and we will define a separate shared memory region for...