• 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.

  • 相关阅读:
    根据JumpServer官方文档搭建服务流程
    Dockerfile常用指令总结(转载)
    高可用集群-lvs
    k8s 基于Kubeadm部署高可用集群
    Docker部署GitLab
    文本处理三剑客-grep
    文件权限
    Docker监控平台
    Redis占用大量内存问题分析
    Annotation
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/2713411.html
Copyright © 2020-2023  润新知