Lập trình .net 4.0 và visual studio 2010 part 16

Nhiệm vụ là một lớp mới đại diện cho công việc bạn muốn hoàn thành. Có nhiều phương pháp để tạo ra, tiến độ, và đồng bộ các nhiệm vụ trong ứng dụng của bạn. | CHAPTER 5 PARALLELIZATION AND THREADING ENHANCEMENTS Tasks Task is a new class that represents the work you want completed. There are methods to create schedule and synchronize tasks in your application. Task Scheduler All the complexity of working with tasks is handled by the task scheduler which in turn works with the main .NET thread pool. You can think of tasks as a wrapper for the thread pool and the preferred way of scheduling threads although there is some additional overhead . The existing thread pool methods will continue to work but tasks are much easier to use and have additional functionality. So how does the task scheduler work 1. When tasks are created they are added to a global task queue. 2. The thread pool will create a number of worker threads. The exact number that are created depends on a number of factors such as the number of cores on the machine current work load type of work load and so on. The thread pool utilizes a hill-climbing algorithm that dynamically adjusts the thread pool to use the optimum number of threads. For example if the thread pool detects that many threads have an I O bottleneck it will create additional threads to complete the work more quickly. The thread pool contains a background thread that checks every seconds to see whether any work has been completed. If no work has been done and there is more work to do a new thread will be created to perform this work. 3. Each worker thread picks up tasks from the global queue and moves it onto its local queue for execution. 4. Each worker thread processes the tasks on its queue. 5. If a thread finishes all the work in its local queue it steals work from other queues to ensure that work is processed as quickly as possible. Note that tasks will steal work from the end of the other task s queues to minimize the chance that the task has started operating with the work already. 6. Figure 5-3 demonstrates this process. 106 CHAPTER 5 PARALLELIZATION AND THREADING ENHANCEMENTS 4 If .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.