This lecture introduces four fundamental operating system (OS) concepts: threads, address spaces, processes, and dual-mode operation. The lecture aims to explain how these concepts contribute to the OS's role as a referee, illusionist, and glue, managing system resources and providing a clean abstraction for programmers.
Threads: A thread represents a single execution context with a program counter, registers, flags, and a stack. Multiple threads can share the same memory space, enabling concurrency and parallelism. The OS multiplexes these threads on a single core to create the illusion of simultaneous execution.
Address Spaces: An address space is the set of memory addresses accessible to a program. Mechanisms like base and bound registers, and more sophisticated page tables, provide memory protection and isolation between processes. Address translation allows the OS to manage memory efficiently and prevent processes from interfering with each other.
Processes: A process is an execution environment with restricted rights, including its own address space and one or more threads. Processes provide protection and isolation between different programs, enhancing reliability and security.
Dual-Mode Operation: This hardware mechanism enables the OS to protect itself and user processes. The processor operates in kernel mode (with full access to resources) and user mode (with restricted access). System calls, interrupts, and exceptions provide controlled transitions between these modes.
The lecture describes address spaces as the set of memory addresses accessible to a program. It highlights that a 32-bit processor, for example, has a view of memory ranging from 0 to 2<sup>32</sup>-1 (approximately 4 billion addresses). This is the processor's perspective; it doesn't mean that physical DRAM exists at every address.
The lecture then explains how the OS uses mechanisms to manage and protect these address spaces. Two main methods are discussed:
Base and Bound Registers: This simpler method uses two registers: a base register indicating the starting address of the allocated memory and a bound register specifying the upper limit. Every memory access is checked against these registers; if an address falls outside the defined range, an error (like a segmentation fault) occurs, preventing access to unauthorized memory regions. This method's limitation is that it is difficult to change the allocation size, potentially requiring copying data if a larger space is needed.
Address Translation (Paging): This more sophisticated method uses a page table to translate virtual addresses (used by the program) into physical addresses (actual locations in DRAM). Each address space is divided into fixed-size chunks called pages, and the page table maps each virtual page to a physical frame in memory. This allows for flexible memory management (pages can be swapped in and out of memory) and strong memory protection. Processes can't directly access each other's memory because their page tables point to different physical locations. The lecture mentions this method is covered in more detail in later lectures.
In essence, address spaces represent the logical view of memory for a program, while the OS employs different translation techniques to map these logical addresses to physical memory, ensuring protection and efficient resource utilization. The simple base and bound method illustrates the fundamental concept of protection, while paging represents a more advanced and practical solution.