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.

  • 相关阅读:
    hdu--1026--Ignatius and the Princess I(bfs搜索+dfs(打印路径))
    hdu--1798--Doing Homework again(贪心)
    开启事务的两种方法
    事务的隔离级别,乐观锁,悲观锁
    树的结构,无限极关联
    微信小程序的加密解密以及小程序的支付
    微信小程序之登录连接django,以及用户的信息授权认证
    微信小程序三
    微信小程序二
    vue-cookies缓存
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/2713411.html
Copyright © 2011-2022 走看看