What is the difference between task and thread?
http://stackoverflow.com/questions/4130194/what-is-the-difference-between-task-and-thread
回答一:
A task is something you want done.
A thread is one of the many possible workers which performs 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 separate threads.
回答2:
In computer science terms, a Task is a future or a promise. (Some people use those two terms synomymously, some use them differently, nobody can agree on a precise definition.) Basically, a Task<T> "promises" to return you a T, but not right now honey, I'm kinda busy, why don't you come back later?
A Thread is a way of fulfilling that promise. But not every Task needs a brand-new Thread. (In fact, creating a thread is often undesirable, because doing so is much more expensive than re-using an existing thread from the threadpool. More on that in a moment.) If the value you are waiting for comes from the filesystem or a database or the network, then there is no need for a thread to sit around and wait for the data when it can be servicing other requests. Instead, the Task might register a callback to receive the value(s) when they're ready.
In particular, the Task does not say why it is that it takes such a long time to return the value. It mightbe that it takes a long time to compute, or it might that it takes a long time to fetch. Only in the former case would you use a Thread to run a Task. (In .NET, threads are freaking expensive, so you generally want to avoid them as much as possible and really only use them if you want to run multiple heavy computations on multiple CPUs. For example, in Windows, a thread weighs 12 KiByte (I think), in Linux, a thread weighs as little as 4 KiByte, in Erlang/BEAM even just 400 Byte. In .NET, it's 1 MiByte!)
What is the difference between task and thread?的更多相关文章
- Difference between Process and thread?
What are the differences between a process and a thread? How are they similar? How can 2 threads com ...
- Task 使用 Task以及Task.Factory都是在.Net 4引用的。Task跟Thread很类似,通过下面例子可以看到。
static public void ThreadMain() { Thread t1 = new Thread(TaskWorker); t1.Start(3); } static public v ...
- Task与Thread间的区别
通过查找一些文章,得知,Task与Thread不可比.Task是为了利用多CPU多核的机制而将一个大任务不断分解成小任务,这些任务具体由哪一个线程或当前线程执行由OS来决定.如果你想自己控制由哪一个T ...
- Linux中的task,process, thread 简介
本文的主要目的是介绍在Linux内核中,task,process, thread这3个名字之间的区别和联系.并且和WINDOWS中的相应观念进行比较.如果你已经很清楚了,那么就不用往下看了. LINU ...
- Scheduler & Task & Worker & Thread & Request & Session & Connection of SQL Server
MSSQL一直以来被人们认为简单.好学,但等到大家掌握了入门操作,深入理解起来又觉得非常的“拧巴”,尤其是对用惯了Oracle的同学来说,究其根本原因,无非是MSSQL引入和暴露了太多的概念.细节和理 ...
- C# 的 Task、Thread、ThreadPool 之间有什么异同?
Thread就是Thread,需要自己调度,适合长跑型的操作. ThreadPool是Thread基础上的一个线程池,目的是减少频繁创建线程的开销.线程很贵,要开新的stack,要增加CPU上下文切换 ...
- c#之task与thread区别及其使用
如果需要查看更多文章,请微信搜索公众号 csharp编程大全,需要进C#交流群群请加微信z438679770,备注进群, 我邀请你进群! ! ! --------------------------- ...
- C#多线程与异步
1.什么是异步同步 如果一个方法被调用,调用者需要等待该方法被执行完毕之后才能继续执行,则是同步. 如果方法被调用后立刻返回,即使该方法是一个耗时操作,也能立刻返回到调用者,调用者不需要等待该方法,则 ...
- Thread比Task多出的无法代替的部分
Task比Thread耗资源更少,且默认在线程池中. 但是Thread能够设置为STA来执行而Task不能,这对于某些特殊功能很重要,比如WebBrowser控件对象就不能在非单线程单元的线程中new ...
随机推荐
- 怎样用Fiddler模拟网络超时
转自:http://materliu.github.io/all/web/2014/04/28/fiddler-timeout.html 用fiddler模拟网络请求超时 用fiddler模拟网络 ...
- Centos6.7 编译安装 MySQL教程
Centos6.7 编译安装 MySQL # 安装依赖包 [root@localhost ~]# yum -y install gcc gcc-c++ autoconf* automake* zlib ...
- more
参数选项: -num 指定屏幕显示大小为num行. +num 从行号num开始显示. -s 把连续多个空行显示为一行. -p 不滚屏,而是清除整个屏幕,然后显示文本. -c 不滚屏,而是从每一屏的顶部 ...
- The Standard SSL Handshake
The following is a standard SSL handshake when RSA key exchange algorithm is used: 1. Client Hello ...
- 调用CAD内的颜色选择对话框
colordialog类 int color; acedSetColorDialog(color,TRUE,0); 第一个函数返回的是颜色的RGB值
- sysbench_mysql
ref http://seanlook.com/2016/03/28/mysql-sysbench/ 测试 当执行下面这个sysbench测试mysql的时候,你不知道的可能可能是: 这到底是在测试读 ...
- java 导入导出的 命令
$exp lddba/ld_321@192.168.1.3/testora file=E:\db_bak\ld20170219_1testora.dmp log=E:\db_bak\ld2017021 ...
- 关于img的一个小知识点
这两天在撸代码的时候发现图片的最下面总是会留一条空白,刚开始不知道为什么,但是UI拿刀对我说去掉它,瑟瑟发抖的我找了下原因及解决方案. 原因:img 是一个inline-block标签,而这个标签的v ...
- 50.percentiles百分比算法以及网站延时统计
主要知识点 percentiles的用法 现有一个需求:比如有一个网站,记录下了每次请求的访问的耗时,需要统计tp50,tp90,tp99 tp50:50%的请求的耗时最长在多长时间 tp90 ...
- 使用 Cordova 打包 app
1.安装nodejs 2.安装 cordova npm install -g cordova 3.Cordova 打包成安卓APK需要用到ANT打包工具,首先配置好java环境: 下载安装Java J ...