http://berb.github.io/diploma-thesis/original/043_threadsevents.html
A mapping of thread-based and event-driven concepts based on Lauer and Needham - 基于Lauer和Needham的基于线程和事件驱动的概念的映射
thread-based
由监视线程
- monitor
- scheduling
- exported functions
- returning from a procedure
- executing a blocking procedure call
- waiting on condition variables
event-driven
异步回调
- event handler
- event loop
- event types accepted by event handler
- dispatching a reply
- dispatching a message, awaiting a reply
- awaiting messages
conclusion
for large-scale connection concurrency, event-driven server architectures using asynchronous/non-blocking I/O operations seem to be more popular, as they provide a slightly better scalability under heavy concurrency.
对于大规模的连接并发,使用异步/非阻塞I/O操作的事件驱动服务器架构似乎更受欢迎,因为它们在重度并发下提供了略好的可扩展性。
threads 基于顺序结构
事件驱动 - 函数式语言和多范式语音通过闭包等特性,缓解了堆栈ripping的问题
当然,这两种模型,谈论的话,离不开实际执行的环境和需要应用的场景!!!
进程 VS 线程
CPU-工厂
进程-车间
线程-工人
浏览器多进程架构
- chrome使用多个进程来隔离不同网页(tab)
- js引擎线程|UI渲染线程|浏览器事件触发线程|HTTP请求线程|定时器触发线程|事件轮询处理线程
- 多线程worker
- JS单线程(run in 浏览器)
- web worker 允许JS脚本创建多个线程,但子线程完全受主线程控制,且不能操作DOM => 同步任务,异步任务
- ajax可以加async:false -> 同步