zoukankan      html  css  js  c++  java
  • System.Threading中Thread和Task区别

    A task is something you want doing.

    A thread is one of possibly many workers who perform that task.

    In .NET 4.0 terms,a Task represents an asynchronous operation.Thread(s) are used to complete that operation by breaking the work up into chunks and assigning to seperate threads.

    Intel TBB and the OpenMP API manage task  scheduling through work stealing.In work stealing,each thread in the thread pool maintains a local task pool that is organized as a deque (double-ended queue). A thread uses its own task pool like a stack,pushing new tasks that it spawns onto the top of this stack.When a thread finishes executing a task,it  first tries to pop a task from the top of its local stack.The task on the top of the task is the newest and therefore most likely to access data that is hot in its data cache.If there are no tasks in its local task pool,however,it attempts to steal work from another thread (the victim).When stealing,a thread uses the victim's deque like a queue so that it steals the oldest task from the victim's deque.For recursive algorithms,these older tasks are nodes that are high in the task tree and therefore are large chunks of work,often work that is not hot in the victim's data cache.Therefore,work stealing is an effective mechanism for balancing load while maintaining cache locality.

    The thread pool and the work-stealing scheduler that distributes work across the threads are hidden from developers when a tasking library is used.Therefore,tasks provide a high-level abstraction that lets users think about the logical parallelism in their application without worrying about managing the parallelism.The load balancing provided  by work-stealing and the low creation and destruction costs for tasks make task-based parallelism an effective solution for most applications.

  • 相关阅读:
    原创《小白的Java自学课》第一课:Java是什么?Java到底能干嘛?
    谷歌chrome浏览器
    QT学习之QPair类
    char 与 signed char 和 unsigned char三者之间的关系
    QT学习之QT判断界面当前点击的按钮和当前鼠标坐标
    QT学习之QScript
    QT Creater 配色方案及下载
    QT学习之QString的arg方法
    QT创建与调用Dll方法(包括类成员)--显式调用
    C++学习之显式类型转换与运行时类型识别RTTI
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/2713411.html
Copyright © 2011-2022 走看看