Book contents
- Frontmatter
- Contents
- Acknowledgments
- Dedication
- 1 Introduction
- 2 From Source File to Executable File
- 3 Variables and Objects; Pointers and Addresses
- 4 Dynamic Allocation and Deallocation of Memory
- 5 Functions and Function Calls
- 6 One-Dimensional Arrays and Strings
- 7 Multi-Dimensional Arrays
- 8 Classes and Objects
- 9 Linked Data Structures
- 10 Memory Leaks and Their Debugging
- 11 Programs in Execution: Processes and Threads
- A Hanoi Towers Puzzle
- B Tracing Objects in C++
- C Tracing Objects and Memory in C++
- D Thread-Safe and Process - Safe Reporting and Logging Functions
- Glossary
- Index
11 - Programs in Execution: Processes and Threads
Published online by Cambridge University Press: 13 January 2010
- Frontmatter
- Contents
- Acknowledgments
- Dedication
- 1 Introduction
- 2 From Source File to Executable File
- 3 Variables and Objects; Pointers and Addresses
- 4 Dynamic Allocation and Deallocation of Memory
- 5 Functions and Function Calls
- 6 One-Dimensional Arrays and Strings
- 7 Multi-Dimensional Arrays
- 8 Classes and Objects
- 9 Linked Data Structures
- 10 Memory Leaks and Their Debugging
- 11 Programs in Execution: Processes and Threads
- A Hanoi Towers Puzzle
- B Tracing Objects in C++
- C Tracing Objects and Memory in C++
- D Thread-Safe and Process - Safe Reporting and Logging Functions
- Glossary
- Index
Summary
Environment and environment variables, command-line arguments and command-line argument structure. A process and its main attributes - user space and process image. Spawning a new process (UNIX fork() system call) from the memory point of view. Principles of interprocess communication; System V shared memory segments and “shared memory leaks”. Threads and lightweight processes; advantages and disadvantages of threads over processes. The need to protect the “common” data in threads. Memory leaks caused by careless multithreading.
In this chapter we will complete the circle that took us through Chapters 2 to 10. This tour of the memory-related aspects of C and C++ programs started with a discussion of programs in execution and how their address spaces relate to memory. Most of what was said in Chapter 2 is not specific to C/C++ programs - it applies to all programs no matter what programming language is used for their creation. However, all the discussions in subsequent chapters assumed a reasonable understanding of that material. Here we return to examining the run-time environment of programs, but now with particular emphasis on the notions of process and thread. As in Chapter 2, most of this material is not specific to C/C++ programs, but an understanding of processes and threads is essential for development of software based on the C/C++ language. The run-time environment of a program is really a matter of the operating system. Nevertheless, when discussing processes and threads, we will focus on the fundamental concepts that are common across various operating systems.
- Type
- Chapter
- Information
- Memory as a Programming Concept in C and C++ , pp. 187 - 209Publisher: Cambridge University PressPrint publication year: 2003