什么是事务内存? [英] What is transactional memory?

查看:73
本文介绍了什么是事务内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑,因为从阅读 wiki 页面来看,它似乎只有一个用于加载和存储的 checkValidate 和提交系统.目的是解决同步问题吗?它是建立在当前硬件之上的软件编程,还是通过 ISA 的硬件实现?每个(HW/SW)实现之间有什么区别?

I'm confused because from reading the wiki page it seems like just having a checkValidate and commit system for loads and stores. Is the purpose to solve synchronization problems? Is it a software programming thing build on-top of current hardware, or is it a hardware implementation via an ISA? What's the difference between each (HW/SW) implementation?

谢谢.

推荐答案

事务内存是使用事务而不是锁来同步并行执行和共享内存的进程的概念.

Transactional Memory is the concept of using transactions rather than locks to synchronise processes that execute in parallel and share memory.

在一个非常简化的层面上,要与锁同步,您需要确定不能由不同线程同时执行的代码段(称为临界区),并在临界区周围获取和释放锁.由于每个锁一次只能由一个线程持有,这保证了一旦一个线程进入临界区,在另一个线程进入受相同锁保护的临界区之前,该部分的所有操作都将完成.

At a very simplified level, to synchronise with locks you identify sections of code (called critical sections) that must not be executed simultaneously by different threads and acquire and release locks around the critical sections. Since each lock can only be held by one thread at a time, this guarantees that once one thread enters a critical section, all of the section's operations will have been completed before another thread enters a critical section protected by the same lock(s).

事务性内存让您可以将代码段指定为事务.事务内存系统(可以在硬件、软件或两者中实现)然后尝试向您保证,多个线程并行执行事务的程序的任何运行将等同于程序的不同运行,其中多个线程并行执行事务交易都一个接一个地执行,绝不会同时执行.

Transactional memory instead lets you designate sections of code as transactions. The transactional memory system (which can be implemented in hardware, software, or both) then attempts to give you the guarantee that any run of a program in which multiple threads execute transactions in parallel will be equivalent to a different run of the program in which the transactions all executed one after another, never at the same time.

事务内存系统通过允许事务并行执行并监控它们对事务变量的访问来实现这一点.如果系统检测到两个事务对同一个变量的访问之间存在冲突,则会导致其中一个事务中止并回滚"到它正在运行的事务的开头;然后它会自动重启事务,系统的整体状态就好像它没有开始之前的运行一样.

The transactional memory system does this by allowing transactions to execute in parallel and monitoring their access to transaction variables. If the system detects a conflict between two transactions' access to the same variable, it will cause one of them to abort and "rollback" to the beginning of the transaction it was running; it will then automatically restart the transaction, and the overall state of the system will be as if it had never started the earlier run.

事务性内存的一个目标是易于编程和安全;一个能够强制正确使用事务的正确实施的 TM 系统提供了硬保证程序中没有并行错误(死锁、竞争条件等),并且只需要程序员指定事务(有时是事务变量,如果系统不只是将所有内存都隐式地视为事务变量),而无需准确识别需要哪些锁,以正确的顺序获取它们以防止死锁等.事务被正确使用"意味着线程之间没有共享数据而不通过事务变量,除了事务之外不能访问事务数据,并且事务内部没有不可回滚"的操作);用于命令式语言(如 C、Java 等)的基于库的软件事务内存系统通常无法强制执行所有这些,这可能会重新引入一些并行性错误的可能性.

One goal of transactional memory is ease-of-programming and safety; a properly implemented TM system which is able to enforce that transactions are used correctly gives hard guarantees that there are no parallelism bugs (deadlocks, race conditions, etc) in the program, and only requires that the programmer designate the transactions (and sometimes transaction variables, if the system doesn't just consider all of memory to implicitly be transaction variables), without needing to identify exactly what locks are needed, acquire them in the correct order to prevent deadlock, etc, etc. "Transacitons are used correctly" implies that there is no sharing data between threads without going through transaction variables, no access to transactional data except in transactions, and no "un-rollbackable" operations inside transactions); library based software transactional memory systems for imperative languages like C, Java, etc generally are unable to enforce all of this, which can re-introduce the possibility of some of the parallelism bugs.

事务内存的另一个目标是增加并行性;如果您有一大堆并行操作访问某些数据结构,所有这些操作可能写入它,但实际上很少写入,那么基于锁的同步通常要求所有操作串行运行以避免数据损坏的机会.事务内存将允许几乎所有操作并行运行,只有在某些进程确实确实写入数据结构时才会失去并行性.

Another goal of transactional memory is increasing parallelism; if you have a whole bunch of parallel operations which access some data structure, all of which might write to it but few of which actually do, then lock-based synchronisation typically requires that all of the operations run serially to avoid the chance of data corruption. Transactional memory would allow almost all of the operations to run in parallel, only losing parallelism when some process actually does write to the data structure.

在实践中(直到我几年前研究我的荣誉项目时),基于硬件的事务内存还没有真正起飞,当前的软件事务内存系统有大量开销.因此,软件事务内存更侧重于合理的性能,可随可用处理器适度扩展且易于编码",而不是为您提供绝对的最大性能.

In practice (as of when I researched my honours project a few years ago), hardware-based transactional memory hasn't really taken off, and current software transactional memory systems have significant overheads. So software transactional memory is more aimed at "reasonable performance that scales with the available processors moderately well and is pretty easy to code", rather than giving you absolute maximal performance.

不过,不同的事务内存系统之间存在很多可变性;我在这里说的是相当抽象和简化的层面.

There's a lot of variability between different transactional memory systems though; I'm speaking at quite an abstract and simplified level here.

这篇关于什么是事务内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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