Threads Module
Role in the System
The purpose of this module is to implement one of the most basic and central components of an operating system -- THREADS. The relevant files are located in the /code/threads directory. Before discussing threads, one must first understand the notion of a PROCESS. A common definition of a process is a program in execution. However, this is a very general definition; a process is both more than a program and less than a program: it is infact simply a unit of work (which progresses sequentially) in an operating system. A process is an active entity, meaning it has a program counter specifying the next instruction to be executed, a stack which includes all relevant addresses used by the process, and set of resources associated with it. A process can be in one of three states:
- ready - the process is set to begin executing its task
- running - the process is currently utilizing the CPU to perform its job
- waiting - the process is idle as it waits for a task to complete
It is possible for a process to create other processes. This is done via a call known as "fork". The original process is the parent, and the processes it creates are its children. A THREAD is a sub-component of a process. It also consists of a program counter, a register set, and a stack space. Since it is part of a process, it shares with its other related threads the same code section, data section and operating system resources. Threads are the means by which one of the goals of an operating system is realized -- efficient use of computing resources. While one thread is waiting for an I/O task to be completed, another can assume control of the CPU to do its job. Furthermore, a scenario can arise where two processes could each potentially corrupt the state of the other. The point at which such a situation could occur is called the "critical section". If the set of instructions are not properly synchronized, chaos could ensue whereby meaningless results are being calculated. The implementation of these concepts is contained in the links below, which are the "third level" decomposition of this module:
Uses Relation