CPU is executing too fast, we feel as if all the tasks are executing at the same time. true parallel multitasking can only be done on multicore CPUs , but because the number of tasks is much larger than the number of cores in the CPU, the operating system automatically shifts many tasks to each core.For the operating system, a task is a process, such as open a browser is to start a browser process, open a notepad started a Notepad process, open two Notepad started the two Notepad process, open
One, Thread processFor the operating system, a task is a process, such as open a browser is to start a browser process, open a notepad started a Notepad process, open two Notepad started the two Notepad process, open a word started a word process. A process is a collection of many resources.Some processes do more than one thing at the same time, such as word, which can be typed, spell-checked, and printed at the same time. Within a process, to do multiple tasks at the same time, you need to run
respective memory is split and controlled by the operating system, which is much more efficient than one program exclusive memory and one queue into memory.Other resources for space reuse also have disks, and in many systems, one disk saves files for many users at the same time. Allocating disk space and documenting who is using which disk block is a typical task for operating system resource management.The combination of these two approaches is a multi-channel technique.Process ThreadsFor the
object [Progress Addobserver:self forkeypath:@void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID) object change: ( Nsdictionary *) Change context: (void *) context{NSLog (@ "progress =%f" , progress.fractioncompleted);} -(void) task{//complete task Unit number +1 if ( Progress.completedunitcount1;} }In the example code above, the Fractioncompleted property is a floating-point value between 0-1 and the completion scale for the task. There are also two string-type properties in the
First, the process
To understand a thread, you first have to mention the concept of "process",
Process: The process is the basis of the operating system structure, is the execution of a program, is a program and its data in the processing machine sequential execution of the action, is the program on a data set running process, it is the system for resource allocation and scheduling of a separate unit.
More specifically: for example,
Each EXE program is a process.
the subtasks to thread to execute . Note that this method must use runnable as the parameter of the thread class, and then create a new thread to execute the subtask through the start () method of the thread. If you call Runnable's Run method, you will not create a new thread, which is no different from a normal method call.In fact, looking at the implementation source code of the thread class will find that the thread class implements the Runnable i
instance, the State may change because the state of the task instance is also changing at the same time. When a task reaches one of its 3 possible final, it can no longer go back to any previous state.
T initial state: The task instance has 3 possible initial states, detailing
Final state: Next, the task instance can transition to the running state and eventually to a final state. If the task instance has associated subtasks, then the
operating system has been greatly improved. Although the development of the process solves the concurrency problem of the operating system, people are still not satisfied, people gradually have a demand for real-time. Because a process can only do one thing in a period of time, if a process has more than one subtask, you can only perform these subtasks on a per-task basis. For example, for a monitoring system, it not only to display the image data on
in which each process has its own address space, memory, data stack, and other secondary data that records its running trajectory. The operating system manages all the processes running on it and distributes the time fairly for those processes. However, each process has its own memory space, data stack, etc., so can only use inter-process communication (inter-process communication, IPC), and can not directly share information.Threads -within a process, to do multiple tasks at the same time, you
address space.Disadvantages of Cache IO:Data is required to perform multiple copies of data in the application address space and the kernel during transmission, and the CPU and memory overhead of these data copy operations is very large.Processes and ThreadsFor the operating system, a task is a process, such as open a browser is to start a browser process, open a notepad started a Notepad process, open two Notepad started the two Notepad process, open a word started a word processSome processes
I. The concept of process and multithreading and the advantages of threadingOpen Windo Task Manager can see a lot of running EXE program, fully can run in memory exe file as a process, the process is a basic operating unit managed by the OS.Threads can be understood as subtasks that run independently in a process. For example, the QQ.exe runtime has many subtasks running at the same time.Using threads, you
greatly improved. Although the development of the process solves the concurrency problem of the operating system, people are still not satisfied, people gradually have a demand for real-time. Because a process can only do one thing in a period of time, if a process has more than one subtask, you can only perform these subtasks on a per-task basis. For example, for a monitoring system, it not only to display the image data on the screen, but also to c
One, Thread processFor the operating system, a task is a process, such as open a browser is to start a browser process, open a notepad started a Notepad process, open two Notepad started the two Notepad process, open a word started a word process. A process is a collection of many resources.Some processes do more than one thing at the same time, such as word, which can be typed, spell-checked, and printed at the same time. Within a process, to do multiple tasks at the same time, you need to run
can implement similar functionality by implementing the Runnable interface. Implementing the Runnable interface must override its Run method.Here is an example:public class Test {public static void Main (string[] args) { System.out.println ("Main thread ID:" + Thread.CurrentThread (). GetId ()); Myrunnable runnable = new myrunnable (); Thread thread = new Thread (runnable); Thread.Start (); }} Class Myrunnable implements Runnable{public Myrunnable () {} @Overridepublic void R
One, Thread processFor the operating system, a task is a process, such as open a browser is to start a browser process, open a notepad started a Notepad process, open two Notepad started the two Notepad process, open a word started a word process. A process is a collection of many resources.Some processes do more than one thing at the same time, such as word, which can be typed, spell-checked, and printed at the same time. Within a process, to do multiple tasks at the same time, you need to run
, what to do, that is, user goals.
With a goal, there is a natural starting point. Just like taking the subway, there are many sites at the beginning to the end. In the physical world it is impossible to cross these intermediate sites. Interactive design is the same, the user in order to complete this goal, the designer needs to decompose this goal, on the reasonable arrangement of these sites, convenient for users to complete each small task simple and smooth. Each subtask must have clear acti
business logic. Master-worker mode (can be used to prepare data before data migration, multiple processes collect data and compute results asynchronously)
The master process is the primary process, maintaining a worker process queue, child task queues, and child result sets. The worker process in the worker process queue extracts the subtasks to be processed from the task queue and writes the results of the subta
Case analysis
Front desk asynchronous upload file to cloud background cron
*/10 * * * */usr/local/bin/php/path/to/upload.php >>/tmp/apkqueue.log
Sometimes uploading a file to the cloud can be time-consuming, a cron has not run out, the next cron is turned on, and a file may be uploaded at the same time as a cron.
If the execution time of a script is much larger than that of Cron, the system will have multiple identical scripts executing simultaneously. If the script's
Cluster:
A cluster is a group of service entities that work together to provide a service platform that is more scalable and available than a single service entity. In the view of the client, a cluster is like a service entity, but in fact the cluster consists of a set of service entities. The cluster provides the following two key features compared to a single service entity:
Scalability--The performance of the cluster is not limited to a single service entity, and new service entities can dy
, or create conditions for the next action. This level can be considered machine instruction level, the operating system level of instruction is derived from this level. Now, we all know clearly that any instruction set is a simple combination of its next level of instruction set. The task that the office clerk wants to complete is actually a series of subtasks. These subtasks are grouped together to form a
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.