与参与者模型和锁相比,事务性存储器是什么 [英] what is transactional memory in comparison to actor model and locks

查看:51
本文介绍了与参与者模型和锁相比,事务性存储器是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与基于actor的同步和基于锁的同步相比,事务存储是什么?

What is the transactional memory in comparison to actor-based and lock-based synchronization?

据我了解,这是并发控制的另一种机制。还是与参与者,事件,锁等完全不同?

As far as I understand it is another mechanism of concurrency control. Or it is something completely different to actors, events, locks etc.?

推荐答案

事务内存(TM)是无锁同步方法。在基于锁的同步机制中,一个线程获取锁并进入同步块,而其他线程等待直到锁可用。在TM中,线程不等待锁,而是继续锁,就像锁可用一样。但是,为了确保执行的正确性,所有在同步块内部进行的存储器访问都是推测性进行的。一旦执行到达同步区域的末尾,线程就会相互通信并共享读取和写入的内存位置(在TM术语中称为读取集和写入集)。如果一个线程读取了另一个线程推测性写入的内存位置,则发生冲突并且将解决冲突。最后,如果两个或多个线程没有冲突,则它们都可以继续并且将使用推测性写入来更新内存。尽管实现过程很复杂,但是通过编写类似于粗粒度锁的程序(只需指定事务的开始和结束),您仍可以获得细粒度锁(基于内存位置)的优点。

Transactional Memory (TM) is a lock free synchronization methodology. In a lock based synchronization mechanism, one thread acquires the lock and enters the synchronized block whilst others wait until the lock becomes available. In TM, threads don't wait for the lock, each of them continue as if the lock is available. However in order to ensure the correctness of the execution, all the memory accesses made inside the synchronized block are made speculatively. Once the execution reaches the end of the synchronized region, threads communicate with each other and share memory locations read and written (called read set and write set in TM terminology). If a thread has read a memory location that has been written speculatively by another thread, a conflict has happened and conflict resolution will takes place. In the end, if two or more threads have no conflicts, they both can continue and will update the memory with speculative writes. Despite the complexity involved with the implementation, you get the advantage of finer grained locking (based on memory locations) with a program written similar to a coarse grained lock (you only need to specify the start and end of a transaction).

根据您如何进行数据版本控制(原始数据与推测性数据)和冲突解决方案(急于-随便做,偷懒-用结束)。

There are dozens of TM systems based on how you do the versioning of data (original data vs speculative data) and conflict resolution (eager - do as you go, lazy - do it in the end). Also the platform they are implemented in (Hardware, Software, HyBrid).

我对基于参与者的并发不是很好。据我所知,它似乎是通过向其他演员发送消息来工作的,每个演员都按照要求执行工作,并在需要时创建更多演员。因此,我认为从概念上讲,它类似于分而治之的风格编程,即动态创建工作并将其传递给可用的演员。类似于函数编程,这种类型的范例与需要同步的传统共享内存样式正交。因此,我猜想基于角色的模型不需要锁或无锁同步,因为它们本质上是并行的。

I am not very good with actor based concurrency. With my limited knowledge, it appears to be working by sending messages to other actors and each actor does the work it is being asked to do and create more actors if it requires. So I guess conceptually it is similar to a divide and conquer style programing where work is created on the fly and being passed around available actors. This type of paradigm, similar to functional programming, goes orthogonal to the traditional shared memory style where synchronization is needed. Therefore I guess, actor based models, do not require locks or lock free synchronization as they are inherently parallel.

这篇关于与参与者模型和锁相比,事务性存储器是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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