I was checking out Intel's "whatif" site and their Transactional Memory compiler (each thread has to make atomic commits or rollback the system's memory, like a Database would).
我正在检查英特尔的“whatif”网站及其事务性内存编译器(每个线程必须进行原子提交或回滚系统的内存,就像数据库那样)。
It seems like a promising way to replace locks and mutexes but I can't find many testimonials. Does anyone here have any input?
这似乎是替换锁和互斥锁的一种有前途的方法,但我找不到很多推荐。这里有人有任何意见吗?
5 个解决方案
#1
8
I have not used Intel's compiler, however, Herb Sutter had some interesting comments on it...
我没有使用英特尔的编译器,但Herb Sutter对此有一些有趣的评论......
From Sutter Speaks: The Future of Concurrency
来自Sutter讲话:并发的未来
Do you see a lot of interest in and usage of transactional memory, or is the concept too difficult for most developers to grasp?
您是否对事务内存有很多兴趣和使用,或者对于大多数开发人员来说这个概念难以理解?
It's not yet possible to answer who's using it because it hasn't been brought to market yet. Intel has a software transactional memory compiler prototype. But if the question is "Is it too hard for developers to use?" the answer is that I certainly hope not. The whole point is it's way easier than locks. It is the only major thing on the research horizon that holds out hope of greatly reducing our use of locks. It will never replace locks completely, but it's our only big hope to replacing them partially.
目前还不能回答谁在使用它,因为它还没有上市。英特尔有一个软件事务内存编译器原型。但如果问题是“开发人员难以使用吗?”答案是我当然希望不会。重点是它比锁更容易。这是研究领域唯一的主要内容,它希望大大减少我们对锁的使用。它永远不会完全取代锁,但它是我们部分替换它们的唯一希望。
There are some limitations. In particular, some I/O is inherently not transactional—you can't take an atomic block that prompts the user for his name and read the name from the console, and just automatically abort and retry the block if it conflicts with another transaction; the user can tell the difference if you prompt him twice. Transactional memory is great for stuff that is only touching memory, though.
有一些限制。特别是,某些I / O本质上不是事务性的 - 您不能使用提示用户输入其名称的原子块并从控制台读取名称,如果它与另一个事务冲突,则自动中止并重试该块;如果你提示他两次,用户可以分辨出差异。但是,事务性内存非常适合仅触及内存的内容。
Every major hardware and software vendor I know of has multiple transactional memory tools in R&D. There are conferences and academic papers on theoretical answers to basic questions. We're not at the Model T stage yet where we can ship it out. You'll probably see early, limited prototypes where you can't do unbounded transactional memory—where you can only read and write, say, 100 memory locations. That's still very useful for enabling more lock-free algorithms, though.
我所知道的每个主要硬件和软件供应商在研发方面都有多个交易记忆工具。有关于基本问题的理论答案的会议和学术论文。我们还没有进入Model T阶段,我们可以将它发布出去。您可能会看到早期的,有限的原型,您无法进行无限制的事务内存 - 您只能读取和写入100个内存位置。不过,这对于启用更多无锁算法仍然非常有用。
#2
4
Dr. Dobb's had an article on the concept last year: Transactional Programming by Calum Grant -- http://www.ddj.com/cpp/202802978
Dobb博士去年有一篇关于这个概念的文章:Calum Grant的交易编程 - http://www.ddj.com/cpp/202802978
It includes some examples, comparisons, and conclusions using his example library.
它包括一些使用他的示例库的示例,比较和结论。
#3
3
I've built the combinatorial STM library on top of some functional programming ideas. It doesn't require any compiler support (except it uses C++17), doesn't bring a new syntax. In general, it adopts the interface of the STM library from Haskell.
我已经在一些函数式编程思想的基础上构建了组合STM库。它不需要任何编译器支持(除了它使用C ++ 17),不会带来新的语法。通常,它采用Haskell的STM库的接口。
So, my library has several nice properties:
所以,我的库有几个不错的属性:
- Monadically combinatorial. Every transaction is a computation inside the custom monad named
STML
. You can combine monadic transactions into more big monadic transactions. - Transactions are separated from data model. You construct your concurrent data model with transactional variables (
TVars
) and run transactions over it. - There is
retry
combinator. It allows you to rerun the transaction. Very useful to build short and understandable transactions. - There are different monadic combinators to express computations shortly.
- There is
Context
. Every computation should be run in some context, not in the global runtime. So you can have many different contexts if you need several independent STM clusters. - The implementation is quite simple conceptually. At least, the reference implementation in Haskell is so, but I had to reinvent several approaches for C++ implementation due to the lack of a good support of Functional Programming.
Monadically组合。每个事务都是名为STML的自定义monad中的计算。您可以将monadic事务组合成更大的monadic事务。
事务与数据模型分开。使用事务变量(TVars)构建并发数据模型并在其上运行事务。
有重试组合器。它允许您重新运行该事务。构建简短且易于理解的事务非常有用。
不久有不同的monadic组合器来表达计算。
有上下文。每个计算都应该在某个上下文中运行,而不是在全局运行时中运行。因此,如果需要多个独立的STM群集,则可以有许多不同的上下文。
从概念上讲,实现非常简单。至少,Haskell中的参考实现是如此,但由于缺乏对功能编程的良好支持,我不得不重新发明几种C ++实现方法。
The library shows very nice stability and robustness, even if we consider it experimental. Moreover, my approach opens a lot of possibilities to improve the library by performance, features, comprehensiveness, etc.
即使我们认为它是实验性的,该库也显示出非常好的稳定性和稳健性。此外,我的方法通过性能,功能,全面性等方式为改进库提供了很多可能性。
To demonstrate its work, I've solved the Dining Philosophers
task. You can find the code in the links below. Sample transaction:
为了展示它的作品,我解决了餐饮哲学家的任务。您可以在下面的链接中找到代码。样品交易:
STML<bool> takeFork(const TVar<Fork>& tFork)
{
STML<bool> alreadyTaken = withTVar(tFork, isForkTaken);
STML<Unit> takenByUs = modifyTVar(tFork, setForkTaken);
STML<bool> success = sequence(takenByUs, pure(true));
STML<bool> fail = pure(false);
STML<bool> result = ifThenElse(alreadyTaken, fail, success);
return result;
};
UPDATE I've wrote a tutorial, you can find it here.
更新我写了一个教程,你可以在这里找到它。
- Dining Philosophers task
- My C++ STM library
餐饮哲学家的任务
我的C ++ STM库
#4
1
Sun Microsystems have announced that they're releasing a new processor next year, codenamed Rock, that has hardware support for transactional memory. It will have some limitations, but it's a good first step that should make it easier for programmers to replace locks/mutexes with transactions and expect good performance out of it.
Sun Microsystems宣布他们将于明年推出代号为Rock的新处理器,该处理器具有对事务内存的硬件支持。它将有一些限制,但这是一个很好的第一步,它应该使程序员更容易用事务替换锁/互斥锁,并期望从中获得良好的性能。
For an interesting talk on the subject, given by Mark Moir, one of the researchers at Sun working on Transactional Memory and Rock, check out this link.
关于这个主题的有趣话题,由Sun研究交易记忆和摇滚的研究人员之一Mark Moir提供,请查看此链接。
For more information and announcements from Sun about Rock and Transactional Memory in general, this link.
有关Sun关于Rock和Transactional Memory的更多信息和公告,请参阅此链接。
The obligatory wikipedia entry :)
必修*条目:)
Finally, this link, at the University of Wisconsin-Madison, contains a bibliography of most of the research that has been and is being done about Transactional Memory, whether it's hardware related or software related.
最后,威斯康星大学麦迪逊分校的这个链接包含了关于交易记忆的大部分研究的参考书目,无论是硬件相关还是软件相关。
#5
-1
In some cases I can see this as being useful and even necessary.
在某些情况下,我可以看到这是有用的,甚至是必要的。
However, even if the processor has special instructions that make this process easier there is still a large overhead compared to a mutex or semaphore. Depending on how it's implemented it may also impact realtime performance (have to either stop interrupts, or prevent them from writing into your shared areas).
但是,即使处理器具有使该过程更容易的特殊指令,与互斥锁或信号量相比仍然存在很大的开销。根据它的实现方式,它也可能会影响实时性能(必须要么停止中断,要么阻止它们写入共享区域)。
My expectation is that if this was implemented, it would only be needed for portions of a given memory space, though, and so the impact could be limited.
我的期望是,如果实现了这一点,那么只需要给定存储空间的某些部分,因此影响可能是有限的。
-Adam
#1
8
I have not used Intel's compiler, however, Herb Sutter had some interesting comments on it...
我没有使用英特尔的编译器,但Herb Sutter对此有一些有趣的评论......
From Sutter Speaks: The Future of Concurrency
来自Sutter讲话:并发的未来
Do you see a lot of interest in and usage of transactional memory, or is the concept too difficult for most developers to grasp?
您是否对事务内存有很多兴趣和使用,或者对于大多数开发人员来说这个概念难以理解?
It's not yet possible to answer who's using it because it hasn't been brought to market yet. Intel has a software transactional memory compiler prototype. But if the question is "Is it too hard for developers to use?" the answer is that I certainly hope not. The whole point is it's way easier than locks. It is the only major thing on the research horizon that holds out hope of greatly reducing our use of locks. It will never replace locks completely, but it's our only big hope to replacing them partially.
目前还不能回答谁在使用它,因为它还没有上市。英特尔有一个软件事务内存编译器原型。但如果问题是“开发人员难以使用吗?”答案是我当然希望不会。重点是它比锁更容易。这是研究领域唯一的主要内容,它希望大大减少我们对锁的使用。它永远不会完全取代锁,但它是我们部分替换它们的唯一希望。
There are some limitations. In particular, some I/O is inherently not transactional—you can't take an atomic block that prompts the user for his name and read the name from the console, and just automatically abort and retry the block if it conflicts with another transaction; the user can tell the difference if you prompt him twice. Transactional memory is great for stuff that is only touching memory, though.
有一些限制。特别是,某些I / O本质上不是事务性的 - 您不能使用提示用户输入其名称的原子块并从控制台读取名称,如果它与另一个事务冲突,则自动中止并重试该块;如果你提示他两次,用户可以分辨出差异。但是,事务性内存非常适合仅触及内存的内容。
Every major hardware and software vendor I know of has multiple transactional memory tools in R&D. There are conferences and academic papers on theoretical answers to basic questions. We're not at the Model T stage yet where we can ship it out. You'll probably see early, limited prototypes where you can't do unbounded transactional memory—where you can only read and write, say, 100 memory locations. That's still very useful for enabling more lock-free algorithms, though.
我所知道的每个主要硬件和软件供应商在研发方面都有多个交易记忆工具。有关于基本问题的理论答案的会议和学术论文。我们还没有进入Model T阶段,我们可以将它发布出去。您可能会看到早期的,有限的原型,您无法进行无限制的事务内存 - 您只能读取和写入100个内存位置。不过,这对于启用更多无锁算法仍然非常有用。
#2
4
Dr. Dobb's had an article on the concept last year: Transactional Programming by Calum Grant -- http://www.ddj.com/cpp/202802978
Dobb博士去年有一篇关于这个概念的文章:Calum Grant的交易编程 - http://www.ddj.com/cpp/202802978
It includes some examples, comparisons, and conclusions using his example library.
它包括一些使用他的示例库的示例,比较和结论。
#3
3
I've built the combinatorial STM library on top of some functional programming ideas. It doesn't require any compiler support (except it uses C++17), doesn't bring a new syntax. In general, it adopts the interface of the STM library from Haskell.
我已经在一些函数式编程思想的基础上构建了组合STM库。它不需要任何编译器支持(除了它使用C ++ 17),不会带来新的语法。通常,它采用Haskell的STM库的接口。
So, my library has several nice properties:
所以,我的库有几个不错的属性:
- Monadically combinatorial. Every transaction is a computation inside the custom monad named
STML
. You can combine monadic transactions into more big monadic transactions. - Transactions are separated from data model. You construct your concurrent data model with transactional variables (
TVars
) and run transactions over it. - There is
retry
combinator. It allows you to rerun the transaction. Very useful to build short and understandable transactions. - There are different monadic combinators to express computations shortly.
- There is
Context
. Every computation should be run in some context, not in the global runtime. So you can have many different contexts if you need several independent STM clusters. - The implementation is quite simple conceptually. At least, the reference implementation in Haskell is so, but I had to reinvent several approaches for C++ implementation due to the lack of a good support of Functional Programming.
Monadically组合。每个事务都是名为STML的自定义monad中的计算。您可以将monadic事务组合成更大的monadic事务。
事务与数据模型分开。使用事务变量(TVars)构建并发数据模型并在其上运行事务。
有重试组合器。它允许您重新运行该事务。构建简短且易于理解的事务非常有用。
不久有不同的monadic组合器来表达计算。
有上下文。每个计算都应该在某个上下文中运行,而不是在全局运行时中运行。因此,如果需要多个独立的STM群集,则可以有许多不同的上下文。
从概念上讲,实现非常简单。至少,Haskell中的参考实现是如此,但由于缺乏对功能编程的良好支持,我不得不重新发明几种C ++实现方法。
The library shows very nice stability and robustness, even if we consider it experimental. Moreover, my approach opens a lot of possibilities to improve the library by performance, features, comprehensiveness, etc.
即使我们认为它是实验性的,该库也显示出非常好的稳定性和稳健性。此外,我的方法通过性能,功能,全面性等方式为改进库提供了很多可能性。
To demonstrate its work, I've solved the Dining Philosophers
task. You can find the code in the links below. Sample transaction:
为了展示它的作品,我解决了餐饮哲学家的任务。您可以在下面的链接中找到代码。样品交易:
STML<bool> takeFork(const TVar<Fork>& tFork)
{
STML<bool> alreadyTaken = withTVar(tFork, isForkTaken);
STML<Unit> takenByUs = modifyTVar(tFork, setForkTaken);
STML<bool> success = sequence(takenByUs, pure(true));
STML<bool> fail = pure(false);
STML<bool> result = ifThenElse(alreadyTaken, fail, success);
return result;
};
UPDATE I've wrote a tutorial, you can find it here.
更新我写了一个教程,你可以在这里找到它。
- Dining Philosophers task
- My C++ STM library
餐饮哲学家的任务
我的C ++ STM库
#4
1
Sun Microsystems have announced that they're releasing a new processor next year, codenamed Rock, that has hardware support for transactional memory. It will have some limitations, but it's a good first step that should make it easier for programmers to replace locks/mutexes with transactions and expect good performance out of it.
Sun Microsystems宣布他们将于明年推出代号为Rock的新处理器,该处理器具有对事务内存的硬件支持。它将有一些限制,但这是一个很好的第一步,它应该使程序员更容易用事务替换锁/互斥锁,并期望从中获得良好的性能。
For an interesting talk on the subject, given by Mark Moir, one of the researchers at Sun working on Transactional Memory and Rock, check out this link.
关于这个主题的有趣话题,由Sun研究交易记忆和摇滚的研究人员之一Mark Moir提供,请查看此链接。
For more information and announcements from Sun about Rock and Transactional Memory in general, this link.
有关Sun关于Rock和Transactional Memory的更多信息和公告,请参阅此链接。
The obligatory wikipedia entry :)
必修*条目:)
Finally, this link, at the University of Wisconsin-Madison, contains a bibliography of most of the research that has been and is being done about Transactional Memory, whether it's hardware related or software related.
最后,威斯康星大学麦迪逊分校的这个链接包含了关于交易记忆的大部分研究的参考书目,无论是硬件相关还是软件相关。
#5
-1
In some cases I can see this as being useful and even necessary.
在某些情况下,我可以看到这是有用的,甚至是必要的。
However, even if the processor has special instructions that make this process easier there is still a large overhead compared to a mutex or semaphore. Depending on how it's implemented it may also impact realtime performance (have to either stop interrupts, or prevent them from writing into your shared areas).
但是,即使处理器具有使该过程更容易的特殊指令,与互斥锁或信号量相比仍然存在很大的开销。根据它的实现方式,它也可能会影响实时性能(必须要么停止中断,要么阻止它们写入共享区域)。
My expectation is that if this was implemented, it would only be needed for portions of a given memory space, though, and so the impact could be limited.
我的期望是,如果实现了这一点,那么只需要给定存储空间的某些部分,因此影响可能是有限的。
-Adam