MindMap Gallery Processes and Threads
This is a mind map about processes and threads. The main contents include: thread status and transitions, threads, process communication, process control, process status and transitions, and processes.
Edited at 2024-10-24 16:49:36This template shows the structure and function of the reproductive system in the form of a mind map. It introduces the various components of the internal and external genitals, and sorts out the knowledge clearly to help you become familiar with the key points of knowledge.
This is a mind map about the interpretation and summary of the relationship field e-book, Main content: Overview of the essence interpretation and overview of the relationship field e-book. "Relationship field" refers to the complex interpersonal network in which an individual influences others through specific behaviors and attitudes.
This is a mind map about accounting books and accounting records. The main contents include: the focus of this chapter, reflecting the business results process of the enterprise, the loan and credit accounting method, and the original book of the person.
This template shows the structure and function of the reproductive system in the form of a mind map. It introduces the various components of the internal and external genitals, and sorts out the knowledge clearly to help you become familiar with the key points of knowledge.
This is a mind map about the interpretation and summary of the relationship field e-book, Main content: Overview of the essence interpretation and overview of the relationship field e-book. "Relationship field" refers to the complex interpersonal network in which an individual influences others through specific behaviors and attitudes.
This is a mind map about accounting books and accounting records. The main contents include: the focus of this chapter, reflecting the business results process of the enterprise, the loan and credit accounting method, and the original book of the person.
Processes and Threads
process
concept
Program: static, a series of instructions
Process: dynamic, the running process of process entities
When a process is created, it is assigned a unique PID
It is an independent unit for resource allocation in the system.
Process entity: static, reflecting the state of the process at a certain moment
Process entity (process image) composition
PCB
service operating system
The information required by the operating system to manage the process is in the PCB
The only sign that a process exists
Program section
Contains program instructions
data segment
Contains various data generated during operation
Characteristics of the process
Dynamic
The most basic characteristics of the process
Concurrency
There are multiple process entities in the memory, executing concurrently
independence
A process is a basic unit that can run independently, obtain resources independently, and receive scheduling independently.
Asynchronicity
Each process moves forward at an independent and unpredictable pace
The operating system must provide a process synchronization mechanism to solve asynchronous problems
structural
Each process will be configured with a PCB, and the process composition structure is the same
Process status and transitions
process status
Created state
Allocate system resources and initialize PCB
ready state
Already have running conditions, CPU is busy, waiting
Running state
Run on CPU
In some cases, after the time slice allocated to the process is used up, the process transitions from the running state back to the ready state.
Only one process is running on a single CPU at the same time
blocking state
The process is waiting for an event to occur and cannot continue to execute. It actively applies for the CPU under system calls.
initiative
When the waiting event occurs, the blocking state returns to the ready state.
passive
three basic states
terminal state
When the process ends, execute the exit system call to the CPU, and the system reclaims the memory space and PCB.
How the process is organized
chain method
The pointer points to the compiled queue
Execution pointer - points to the running process
Ready queue pointer - points to the ready process
Blocking queue pointer - points to the blocked process (different queues for different blocking reasons)
Index mode
Create index tables for processes in different states
Index table points to PCB
process control
Basic concepts
Process control is to realize the conversion of process state
Process control is implemented using primitives
Primitives implemented with on/off interrupts
A primitive is a special kind of program
Execution of primitives cannot be interrupted
Related primitives
Create primitives
Termination primitive
blocking primitive
wake primitive
Blocking and wakeup come in pairs
switch primitive
Thread status and transitions
States and transitions
Run->Block
Wait for something to happen
Blocked->Ready
The event is over
Ready->Run
selected by scheduler
Run->Ready
Time slice ran out
organization and control
Multiple TCBs are organized into thread tables
thread
Thread is the basic CPU execution unit and the smallest unit of program execution flow.
Traditional processes can only execute a series of programs serially. To this end, threads are introduced to increase concurrency and allow concurrent execution of programs within the process.
Processes now only serve as allocation units for system resources other than the CPU
After the introduction of processes, the system overhead caused by concurrency is reduced
Thread properties
Thread is the unit of processor scheduling
In a multi-core CPU, each thread can occupy different CPUs
Each thread has a thread ID, thread control block TCB
three basic states
ready
block
run
Threads basically do not own system resources
Different threads in the same process share system resources
How threads are implemented
user-level thread
Used in early operating systems, when "threads" were implemented by thread libraries
Such as three pieces of concurrent code in the while loop
Kernel level threads
Threads are implemented by the operating system
multi-threaded model
One to one
A user-level thread maps to a kernel-level thread
advantage
Each thread can be assigned to a multi-core processor for parallel execution, with a high degree of concurrency.
shortcoming
Thread management requires operating system support and is expensive
many to one
Multiple user-level threads are mapped to one kernel-level thread, and only one kernel-level thread is allocated to a process.
advantage
Thread management overhead is small and efficient
shortcoming
Blocking a user-level thread will cause process blocking and low concurrency.
many to many
compromise method
process communication
shared storage
Set up a shared memory area and map it into the process's virtual address space
Each process accesses the shared area mutually (the communicating process itself is responsible for implementing mutual exclusion)
two ways
Based on data structures (low level)
Bucket-based sharing (advanced)
messaging
Deliver structured messages (message header & message body)
The system provides sending primitives and receiving primitives
two ways
direct communication
The message is directly placed in the message queue of the receiving process.
Mailbox communication method
The message is stored in the intermediate
pipe communication
Set up a special shared file "pipeline" (memory buffer)
Pipes can only achieve half-duplex communication
Achieving two-way simultaneous communication requires two pipes
Each process accesses the pipe mutually (operating system implements mutual exclusion)
The write process blocks when the writing is full, and the read process blocks when the reading is empty.