螺纹与异步 [英] Threads vs. Async

查看:132
本文介绍了螺纹与异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读了关于编程与从这个真的好文章异步模型的线程模型。 http://krondo.com/blog/?p=1209

然而,文中提到以下几点。


  1. 异步程序会简单地通过每当有一个I / O任务之间切换跑赢大市同步程序。

  2. 线程是由操作系统进行管理。

我记得读线程被操作系统深受各地就绪队列和等待队列之间移动的TCB(除其他队列)进行管理。在这种情况下,线程不会等待上浪费时间或者做自己?

在上面所说的光,在什么线程程序是异步方案的优势是什么?


解决方案

  1. 这是非常难写code,它是线程安全的。随着asyncronous code你知道究竟在何处code会从一个任务转移到下一个和种族条件,因此也更难得到。

  2. 线程消耗数据,因为每个线程都需要有其自身的堆栈中的相当数量;与异步code所有code股相同的堆栈和栈是由于不断展开任务的堆栈保持很小。

  3. 线程是操作系统的结构,因此该平台,以支持更多的内存。没有与异步任务没有这样的问题。

I have been reading up on the threaded model of programming versus the asynchronous model from this really good article. http://krondo.com/blog/?p=1209

However, the article mentions the following points.

  1. An async program will simply outperform a sync program by switching between tasks whenever there is a I/O.
  2. Threads are managed by the operating system.

I remember reading that threads are managed by the operating system by moving around TCBs between the Ready-Queue and the Waiting-Queue(amongst other queues). In this case, threads don't waste time on waiting either do they?

In light of the above mentioned, what are the advantages of async programs over threaded programs?

解决方案

  1. It is very difficult to write code that is thread safe. With asyncronous code you know exactly where the code will shift from one task to the next and race conditions are much therefore much harder to come by.
  2. Threads consume a fair amount of data since each thread needs to have its own stack; with async code all the code shares the same stack and the stack is kept small due to continuously unwinding the stack between tasks.
  3. Threads are OS structures and are therefore more memory for the platform to support. There is no such problem with asynchronous tasks.

这篇关于螺纹与异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆