当前位置:网站首页>Process communication and thread explanation
Process communication and thread explanation
2022-07-04 11:17:00 【loveCC_ orange】
2.6 Process of communication
- Process of communication : Refers to the exchange of information between processes
- Basic communication : Only some states and a small amount of data are exchanged between processes . Such as : Mutual exclusion and synchronization between processes
Disadvantages of semaphore mechanism as a communication tool :
- 1、 Low efficiency
- 2、 Communication is not transparent to users
Advanced communications : A large amount of data can be exchanged between processes
- Users can directly use a set of communication commands provided by the operating system , A group of communication methods that efficiently transmit large amounts of data .
- The operating system hides the details of process communication , Transparent to users , It reduces the complexity of communication programming .
Process of communication ( Advanced communications )
- One 、 The type of process communication
- Two 、 The implementation of message passing communication
- 3、 ... and 、 Some problems in the implementation of message passing system
- Four 、 Message buffer queue communication mechanism
One 、 The type of process communication
Advanced communication mechanisms can be divided into three categories :
- Shared memory system
- Messaging system
- Pipeline communication system
1、 Shared memory system
Processes that communicate with each other share certain data structures or shared storage areas , Communicate through these spaces .
Communication mode based on shared data structure ( Basic communication )
Processes share certain data structures , So as to realize the information exchange between processes
Realization :
Setting of public data structure and processing of inter process synchronization , It's all the responsibility of programmers .
operating system – Provide shared memory
characteristic : Inefficient . It is only suitable for transmitting a relatively small amount of data .Communication mode based on shared memory area
Mark out a shared storage area in the storage area , Processes can communicate by reading or writing data in shared memory .
2、 Messaging system
- Data exchange between processes , In formatted messages .
- Programmers directly use a set of communication commands provided by the system ( The original language ) communicate .
- example : computer network : Network message
3、 Pipeline communication
Two 、 The implementation of message passing communication
1、 Using direct communication primitives to solve producer problems - Consumer issues
When a producer produces a commodity ( news ) after , Easy to use send The primitive sends the message to the consumer process ; Consumer processes take advantage of receive The primitive gets a message . If the news hasn't come out yet , Consumers have to wait , Until the producer process sends the message .
2、 Indirect communication ------ Communicate through mailbox
- The mailbox is used to temporarily store messages sent by the sending process to the target process , The receiving process takes the message sent to itself from the mailbox .
- Messages can be safely saved in the mailbox , Only approved target users are allowed to read at any time
- Use mailbox , It can communicate in real time , And non real-time communication .
- Mailboxes can be created by the operating system , It can also be created by user processes , The creator is the owner of the mailbox .
Mailbox classification :
Private mailbox User processes create their own A one-way
Public mailbox Operating system creation two-way
Shared mailbox A process is created
The difference between public mailbox and shared mailbox : The creator is different .
3、 ... and 、 Some problems in the implementation of message passing system
1、 communication link
classification :
(1) According to the establishment mode of communication link :
- Explicit connection : First use “ Establishing a connection ” command ( The original language ) Establish a communication link ; communicate ; Then remove the link in an explicit way . For computer networks .
- Implicit connection : The sending process does not need to explicitly put forward the requirements for establishing links , Directly use the sending command provided by the system ( The original language ), The system will automatically establish a link for it . For stand-alone systems .
2、 Format of message
- Stand alone system environment : The environment is the same , The message format is simple
- Computer network environment : The environment is different , The transmission distance of the message is very long, and the message format is relatively complex .
3、 Process synchronization mode
When communicating between processes , Supplemented by process synchronization mechanism , Enable coordinated communication between processes .
The sending process or receiving process completes the sending or receiving of the message , There are two possibilities : Process or continue sending ( receive ) Or blocked .
The sending process is blocked 、 The receiving process is blocked ( Tight synchronization There is no buffer , The data sent by the sending process is directly received by the receiving process )
The sending process is not blocked 、 The receiving process is blocked ( Sending speed < Reception speed )
Neither the sending process nor the receiving process is blocked ( The sending speed is similar to the receiving speed , Basic synchronization )
Four 、 Message buffer queue communication mechanism
principle :
(2)PCB Data item about communication in
2、 Send primitive
3、 Receive the original
2.7 Basic concept of thread
Thread Introduction
1、 Two basic properties of a process
(1) A process is an independent unit that can have resources
(2) A process is a basic unit that can be independently scheduled and dispatched
This makes the process a basic unit that can run independently , It forms the basis of process concurrent execution .
2、 The time and space cost of program concurrent execution
- Process owns resources , Make the creation of the process 、 Revocation and scheduling cost a lot of time and space .
- This limits the number of processes set up in the system , And process switching should not be too frequent , This limits the further improvement of concurrency .
- therefore , Separate the two attributes of the process from the system , among The second property is determined by the thread To achieve .
3、 Threads —— As the basic unit of scheduling and allocation
- Light entity
- The basic unit of independent scheduling and dispatching
- Can be executed concurrently
- Share process resources
Comparison between thread and process
- The basic unit of dispatch
When introducing threads OS in , Thread has been regarded as the basic unit of scheduling and dispatching , Therefore, thread is the basic unit that can run independently . When threads switch , Only a small amount of register contents need to be saved and set , The switching cost is much lower than the process . In the same process , Thread switching will not cause process switching , But when switching from a thread in one process to a thread in another process , It will inevitably cause process switching . - concurrency
When introducing threads OS in , Not only can processes execute concurrently , Moreover, multiple threads in a process can execute concurrently , It even allows all threads in a process to execute concurrently . Again , Threads in different processes can also execute concurrently . - Has the resources
Processes can have resources , And as a basic unit of resources in the system . However, threads do not own system resources , But only a little essential 、 Resources that can guarantee independent operation . - independence
The independence between different threads in the same process is much lower than that between different processes . Because it is necessary to prevent mutual interference and destruction between processes , Each process has an independent address space and other resources , In addition to sharing global variables , Do not allow other processes to access . But different threads in the same process are often created to improve concurrency and cooperate with each other , They share the memory address space and resources of the process , For example, each thread can access all addresses in the process address space to which they belong , For example, the stack of a thread can be read and written by other threads , Even completely clear . Files opened by one thread can be read by other threads 、 Write . - overhead
The cost of thread creation and revocation is much lower than that of the process , During thread switching , The cost is also far lower than the process . - Support multiprocessor systems
About the basic state of threads , be ready 、 Execution and blocking are similar to processes
About thread control block TCB, And PCB similar .
- Thread identifier , Give each thread a unique thread identifier
- A set of registers , Including program registers PC, Contents of status register and general register
- Thread running state , Used to describe the running state of a thread
- priority , Describes the priority of thread execution
- Thread specific storage , Used to store on-site protection information during thread switching , And statistics related to the thread
- Signal shielding , Shield some signals
- Stack pointer , When the thread is running , Procedure calls are often made
Thread control block TCB, Used to record all information used to control and manage threads .
Multithreading OS The process of has the following properties
- A process is a basic unit of owning resources
- Multiple threads can execute concurrently
- The process is no longer an executable entity
边栏推荐
- Heartbeat启动后无反应
- Performance features focus & JMeter & LoadRunner advantages and disadvantages
- 2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
- Installation of ES plug-in in Google browser
- Canoe-the second simulation project-xvehicle-1 bus database design (idea)
- Supercomputing simulation research has determined a safe and effective carbon capture and storage route
- Heartbeat报错 attempted replay attack
- How to deal with the relationship between colleagues
- re. Sub() usage
- Canoe - description of common database attributes
猜你喜欢
Canoe - the third simulation project - bus simulation - 2 function introduction, network topology
[test theory] test process management
Take advantage of the world's sleeping gap to improve and surpass yourself -- get up early
Application of slice
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
Properties and methods of OS Library
JMeter common configuration components and parameterization
Fundamentals of software testing
Canoe - description of common database attributes
SQL greatest() function instance detailed example
随机推荐
VPS安装Virtualmin面板
Locust installation
Solaris 10 network services
Climb Phoenix Mountain on December 19, 2021
CAPL: on sysVar_ Update difference on sysvar
Canoe test: two ways to create CAPL test module
QQ group administrators
SQL greatest() function instance detailed example
Function introduction of canbedded component
Usage of with as
Canoe: the difference between environment variables and system variables
Is Sanli futures safe? How to open a futures account? How to reduce the handling charge of futures at present?
JMeter common configuration components and parameterization
三立期货安全么?期货开户怎么开?目前期货手续费怎么降低?
Canoe - the third simulation project - bus simulation - 2 function introduction, network topology
Introduction to canoe automatic test system
[advantages and disadvantages of outsourcing software development in 2022]
VPS installation virtualmin panel
Postman interface test
Unittest+airtest+beatiulreport combine the three to make a beautiful test report