In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to realize the cooperation process of PHP7". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
What is a cooperative process?
First of all, let's figure out what a cooperative journey is.
You may have heard of the concepts of "process" and "thread".
A process is a running instance of a binary executable file in computer memory, just as your .exe file is a class, and the process is the instance from new.
Process is the basic unit of resource allocation and scheduling in computer system. Each CPU can only handle one process at a time.
The so-called concurrency is just that it looks as if CPU can handle several things at the same time, for single-core CPU is actually switching different processes at a very fast speed.
The switching of the process requires a system call, and the CPU needs to save all the information of the current process, and at the same time it will make the CPUCache obsolete.
So don't do the process switch unless you have to.
So how to achieve "do not do it unless the process has to be switched"?
First of all, the conditions for the process to be switched are: the completion of the process execution, the end of the CPU time slice allocated to the process, the interruption of the system to deal with, or the process waiting for the necessary resources (process blocking) and so on. If you think about it, there is naturally nothing to say in the first few cases, but if you are blocking and waiting, is it a waste?
In fact, if there is a blockage, there are other places where our program can be executed, so we don't have to wait foolishly.
So there are threads.
A thread is simply a "microprocess" that runs a function (logical flow).
So we can use threads to reflect the functions that can be run at the same time in the process of writing the program.
There are two types of threads, one is managed and scheduled by the kernel.
We say that as long as the kernel is involved in the management and scheduling, the cost is very high. This kind of thread actually solves the problem that when an executing thread encounters a block in a process, we can schedule another runnable thread to run, but it is still in the same process, so there is no process switching.
There is another type of thread whose scheduling is managed by programmers who write their own programs and are invisible to the kernel. This kind of thread is called "user space thread".
The co-program can be understood as a kind of user space thread.
The cooperative process has several characteristics:
Collaboration, because it is a scheduling policy written by programmers themselves, which switches through collaboration rather than preemption
Create, switch and destroy in user mode
From a programming point of view, the idea of ⚠️ is essentially the active yield and resume mechanism of control flow.
Generator is often used to implement collaborative programs.
Speaking of which, you should understand the basic concept of Xiecheng, right?
PHP implements the cooperative program
Step by step, start with explaining the concept!
Iterable object
PHP5 provides a way to define objects so that they can be traversed through a list of cells, such as the foreach statement.
If you want to implement an iterable object, you need to implement the Iterator interface:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.