从编程者角度,thread是一段顺序执行的代码,actor是一个可以接受外界消息加以处理,然后将处理结果通过消息发给外界的一个功能块。actor模型比thread更好用,并行编程的很多东西actor都帮你处理好了,只管拿来用,不用手动处理线程同步,消息收发等细节。
从操作系统/框架角度,thread的并行执行只需要进行上下文切换(context switch),actor将thread和私有数据,异步通信,事件响应有机结合在一起的一个编程模型。
至于各自优势,actor降低并行编程的门槛,可以更快速的开发出自带最佳实践的多线程程序,thread则可以让有经验的人手动处理多线程之间的同步,消息收发,定制出更符合自己需要的代码。
关于thread和actor下面这段话讲的很好
Experienced developers have learned to be very careful with unrestricted threads and various blocking mechanisms of a (real-time) operating system, because they often lead to programs that are unsafe and difficult to reason about. Instead, experts apply the following best practices of concurrent programming:
1.Keep data isolated and bound to threads. Threads should hide (encapsulate) their private data and other resources, and not share them with the rest of the system.
2.Communicate among threads asynchronously via messages (event objects). Using asynchronous events keeps the threads running truly independently, without blocking on each other.
3.Threads should spend their lifetime responding to incoming events, so their mainline should consist of an event-loop that handles events one at a time (to completion), thus avoiding any concurrency hazards within a thread itself.
While these practices can be applied manually on top of the "free threading" approach, a better way is to use the Active Object (Actor) pattern, which inherently supports and automatically enforces the best practices of concurrent programming.