1、附录 一 Compared to multi-threaded operating system, means is that it can run a program with the ability of different parts; each part of the implementation was as a thread. Therefore, in the preparation of applications, we have very good design in order to avoid the implementation of the different thr
2、eads of mutual interference. Which will help us to design robust procedures, we can make at any time when necessary to add the thread. Thread can be described as a micro-process; it has a starting point for the implementation of the order of series and a destination. It is responsible for the mainte
3、nance of its own stack, the stack for exception handling, priority scheduling and a number of other threading systems re-implementation of the information needed. From this concept, it seems there is no thread with the process of distinction, in fact, thread and process is certainly different: the p
4、rocess of a complete independence to have their own memory space and data, but the same thread within a process is shared memory space and data. Corresponds to a process for some procedures, it is by the same procedure in which an independent threads running at the same time the composition. Thread
5、is sometimes referred to as parallel program running on lightweight processes, threads are lightweight processes called because it is dependent on the operation and process the context of the environment, and the process of using resources. In a process, the threads are preemptive scheduling or non-
6、preemptive model. In seizing the model, the operating system responsible for the allocation of CPU time for each process, once the current process used to finish the distribution of CPU time, the next operating system will determine the CPU time is occupied by a single thread. Thus the operating sys
7、tem will periodically interrupt the current thread is running, the allocation will be cup to the next in the queue waiting for a thread. Therefore, a thread can not be any exclusive CPU. Occupied by each thread CPU time depends on the process and the operating system. Process assigned to each thread
8、 a short period of time that we feel all the threads are executed at the same time. In fact, the system time for each process, 2 ms, and then scheduling other threads. It the same time, he maintained all the threads and circulation, the distribution of small amount of CPU time to the thread. Thread
9、switching and scheduling is so fast that the feeling is that all the threads are executed simultaneously. What does scheduling mean? Scheduling processor storage means to be implemented by the end of the process of CPU time for the state and a future time loading the state of the process to resume i
10、ts operation. In this way, however there are deficiencies, one thread at any given time interruption of the implementation of a thread. Suppose a thread is a document does write operation, and another thread interrupts its operation, also the same documents do write operation. Windows 95/NT, UNIX is
11、 used in such a way thread scheduling. In non-preemptive scheduling model, each thread may need to occupy much time CPU time CPU. Scheduling in this way, it may be a very long execution time makes all the other threads need to thread CPU starving to death. In the processor is idle, that is, when the
12、 process does not use CPU, the system can allow the process of temporarily using other CPU. CPU occupation CPU thread has the power to control the release of only its own initiative, CPU; other threads can use the CPU. Some I / O and Windows 3.x is the use of this scheduling strategy. In some operat
13、ing systems inside, which will use two scheduling strategy. Non-preemptive scheduling strategy of running in the thread priority when used in general, and for high-priority scheduling of threads is the use of preemptive scheduling strategy. If you are unsure about the kind of system is that scheduli
14、ng strategy, assuming that the scheduling strategy can not be seized is relatively safe to use. Application in the design, we believe that those who occupy a relatively large number of CPU time for a certain interval thread will release the control of the CPU, this time the system will check the que
15、ue of those waiting inside the thread currently running with the same priority level or higher priority threads, and thread to use these CPU. If you find such a system of thread, immediately suspend the currently executing thread and activate the thread satisfy certain conditions. If you do not find
16、 the same or higher-priority thread, the current thread has also continued to occupy CPU. When the thread is running CPU would like to release control to a low priority thread, the current thread into sleep state to allow low-priority threads hold the CPU. In a multi-processor system, the operating
17、system will these independent threads allocated to the different processor implementation, this will greatly speed up the process of running. The implementation of the efficiency of the thread will be greatly improved, because the threads of time-sharing a single processor into a distributed multi-p
18、rocessor implementation. This multi-processor in the three-dimensional modeling and graphics processing is very useful. Do you need to multi-threaded? We sent a print order requesting the printer to print tasks, assuming that this time in response to the computer and the printer stopped working also
19、, would it mean that we do things to stop waiting for this slow on the printer? Fortunately, this situation does not occur, we work in the printer can also listen to music or drawing. Because we use a separate threads to perform these tasks. May you have multiple users simultaneous access to a datab
20、ase or web server was surprised at how they work? This is because for each connected to a database or web server user set up an independent thread to maintain the status of the user. If a program is running a certain degree of order, this time in this way problem may arise, and even lead to the coll
21、apse of the entire process. If the program can be divided into different independent tasks, the use of multi-threaded, even if a certain part of the task failed, on the other would not be affected, will not lead to the collapse of the entire process. There is no doubt that the procedures for the pre
22、paration of multi-threaded tool makes you a slave to drive the process of non-multi-threaded, multi-threaded but may also become a burden or cost need not be small. If the improper use of it will bring more of the disadvantages. If a program has a lot of threads, then the thread is bound to other pr
23、ograms can only take up less CPU time; and a lot of CPU time is used for thread scheduling; operating system also requires sufficient memory space to maintain each thread context information; therefore, a large number of threads will reduce the efficiency of system operation. Therefore, if the use o
24、f multi-threaded, then the multi-threaded program must be designed well, otherwise the benefits will be far less than the disadvantages. The use of multi-threaded so we must be careful to deal with these threads of the creation, scheduling and work release. There are many ways to design multi-threaded applications. As shown in the back of the article, I will give detailed examples of programming, through these examples; you will be able to better understand the multi-threaded. Threads can have different priorities, for