Re:用于C ++ 0x的同步算法验证器 [英] Re: Synchronization Algorithm Verificator for C++0x

查看:48
本文介绍了Re:用于C ++ 0x的同步算法验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

On2á×?,20:47,Dmitriy V''jukov < dvyu ... @ gmail.comwrote:

On 2 á×?, 20:47, "Dmitriy V''jukov" <dvyu...@gmail.comwrote:


我想宣布名为Relacy Race Detector的工具,我已经

发达。它是C ++ 0x'的同步算法验证器'

宽松的内存模型。
I want to announce tool called Relacy Race Detector, which I''ve
developed. It''s synchronization algorithm verificator for C++0x''s
relaxed memory model.



问:我可以使用Relacy Race Detector检查我的algo againts其他C

++ 0x内存模型(x86,PPC, Java,CLI)?

A是的,你可以。幸运的是,C ++ 0x内存模型是非常放松的,因此主要部分是b> b,它是超集。基本上任何其他记忆

模型。你只需要定义绑定即可。你的目标内存之间

模型和C ++ 0x内存模型。


让我们创建这样的绑定,例如,对于x86内存模型: br />
- 普通加载操作总是获取 (即

memory_order_acquire)

- 普通商店操作总是释放。 (即

memory_order_release)

- 原子RMW操作总是顺序一致的(即

memory_order_seq_cst)

- mfence指令是

std :: atomic_thread_fence(memory_order_seq_cst)

就是这样。您可以为其他硬件内存创建此类绑定
您感兴趣的
模型(PPC,Itatium,SPARC等)。


您可以定义此类绑定其他抽象的内存模型,比如

Java MM。让我们看看:

- 普通负载是放松的(即memory_order_relaxed)

- 普通商店是放松的(即memory_order_relaxed)

- 易变负载是获得 (即memory_order_acquire)

- 易失性存储操作是释放 (即memory_order_release)

- 原子RMW操作总是顺序一致的(即

memory_order_seq_cst)

但这里有一些警告。首先,你必须模拟GC的工作,即

将所有已分配的内存放入特殊列表,并在test_suite :: after()中释放所有已分配的内存。其次,你必须在每个易失性存储和

易失性负载之间手动发出

顺序一致的内存栅栏。第三,您必须手动将所有变量初始化为

默认值(0)。第四,没有数据竞争这样的东西,所以你必须将所有变量定义为std :: atomic,这将有效地实现
禁用数据竞争检测机制。好吧,实际上你可以使用

rl :: var变量,如果你知道必须没有并发

访问变量,这将启用一些自动错误检测

wrt数据竞赛。

听起来不是很酷......所以我要添加内置的Java支持

和CLI。然后用户必须定义​​类似RL_JAVA_MODE /

RL_CLI_MODE的东西,并获得所有这些开箱即用的东西。但是,它是

仍然是C ++库。您怎么看?


Dmitriy V'''jukov


Q: Can I use Relacy Race Detector to check my algo againts other that C
++0x memory models (x86, PPC, Java, CLI)?
A Yes, you can. Fortunately, C++0x memory model is very relaxaed, so
for the main part it''s a "superset" of basically any other memory
model. You just have to define "binding" between your target memory
model and C++0x memory model.

Let''s create such binding, for example, for x86 memory model:
- plain load operation is always "acquire" (i.e.
memory_order_acquire)
- plain store operation is always "release" (i.e.
memory_order_release)
- atomic RMW operation is always sequentially consistent (i.e.
memory_order_seq_cst)
- mfence instruction is
std::atomic_thread_fence(memory_order_seq_cst)
That is all. You can create such bindings for other hardware memory
models you are interested in (PPC, Itatium, SPARC etc).

And you can define such binding to other abstract memory model, like
Java MM. Let''s see:
- plain load is "relaxed" (i.e. memory_order_relaxed)
- plain store is "relaxed" (i.e. memory_order_relaxed)
- volatile load is "acquire" (i.e. memory_order_acquire)
- volatile store operation is "release" (i.e. memory_order_release)
- atomic RMW operation is always sequentially consistent (i.e.
memory_order_seq_cst)
But here are some caveats. First, you have to emulate work of GC, i.e.
put all allocated memory to special list, and free all allocated
memory in test_suite::after(). Second, you have to manually emit
sequentially consistent memory fence between every volatile store and
volatile load. Third, you have to manually initialize all variables to
default value (0). Fourth, there is no such thing as data race, so you
have to define all variables as std::atomic, this will effectively
disable data race detection mechanizm. Well, actually you can use
rl::var variables, if you know that there must be no concurrent
accesses to variable, this will enable some automatic error detection
wrt data races.
Sounds not very cool... So I''m going to add built-in support for Java
and CLI. Then user would have to define something like RL_JAVA_MODE/
RL_CLI_MODE, and get all those things out-of-the-box. But yes, it
still will be C++ library. What do you think?

Dmitriy V''jukov

推荐答案

我已经上传了版本1.2的Relacy种族探测器:
http://groups.google.com/group / relacy / files


该版本的主要特性是支持Java / CLI(又名.NET)

算法验证(但不要不要混淆 - 它仍然是C ++

库。)

支持包括以下内容:

- GC模拟:只是分配 - 忘记。 GC消除了与无锁算法相关的重要问题 - 安全内存
回收和ABA问题。您可以使用GC并在C ++模式下 - 只需

定义RL_GC。

- CLI内存模型。更强大的原子RMW操作和更强大的

seq_cst围栏。

- Java内存模型。更强大的原子RMW操作和更强大的

seq_cst围栏和seq_cst围栏在易失性

存储和易失性负载之间自动发出。

- 与之关联的基本CLI API同步。 rl :: nvolatile<>

类模拟CLI挥发性。 rl :: nvar<模拟普通的CLI变量。

rl :: Interlocked命名空间中可用的互锁操作(即

rl :: Interlocked :: CompareExchange())。还有

rl :: Thread :: MemoryBarrier(),rl :: Thread :: VolatileRead(),

rl :: Thread :: VolatileWrite()和rl: :Thread :: SpinWait()。

- 与sycnronization相关的基本Java API。 rl :: jvolatile<>,

rl :: jvar<> ;, rl :: AtomicInteger和rl :: AtomicLong。请注意,不会模拟大量的

Java / CLI支持库(各种ConcurrentQueue的

等)。但您可以使用互斥锁,condition_variables,信号量

以及来自C ++ API,POSIX API或Win API的事件。


您可以在此处看到CLI算法验证的示例:
http://groups.google.com /group/relac...1c913c298a20ab


Java示例:
http://groups.google.com/group/relac...7150359b8fb57d


另外发布包括一些错误修复。


期待您的评论。


Dmitriy V''jukov
I have uploaded release 1.2 of Relacy Race Detector:
http://groups.google.com/group/relacy/files

The main feature of the release is support for Java/CLI (aka .NET)
algorithm verification (but don''t get confused - it''s still C++
library).
The support includes following things:
- Emulation of GC: just allocate-and-forget. GC eliminates important
problems associated with lock-free algorithms - safe memory
reclamation and ABA problem. You can use GC and in C++ mode - just
define RL_GC.
- CLI memory model. Stronger atomic RMW operations and stronger
seq_cst fence.
- Java memory model. Stronger atomic RMW operations and stronger
seq_cst fence and seq_cst fence emitted automatically between volatile
store and volatile load.
- Basic CLI API associated with synchronization. rl::nvolatile<>
class emulates CLI volatiles. rl::nvar<emulates plain CLI variables.
Interlocked operations available in rl::Interlocked namespace (i.e.
rl::Interlocked::CompareExchange()). And also
rl::Thread::MemoryBarrier(), rl::Thread::VolatileRead(),
rl::Thread::VolatileWrite() and rl::Thread::SpinWait().
- Basic Java API associated with sycnronization. rl::jvolatile<>,
rl::jvar<>, rl::AtomicInteger and rl::AtomicLong. Note that extensive
Java/CLI support libraries are not emulated (various ConcurrentQueue''s
and so on). But you can use mutexes, condition_variables, semaphores
and events from C++ API, POSIX API or Win API.

Example of CLI algorithm verification you can see here:
http://groups.google.com/group/relac...1c913c298a20ab

Java example:
http://groups.google.com/group/relac...7150359b8fb57d

Also release includes a bunch of bug fixes.

Looking forward to your comments.

Dmitriy V''jukov


我上传了Relacy Race Detector 1.2版:
http://groups.google.com/group/relacy/files

Dmitriy V''jukov
I have uploaded release 1.2 of Relacy Race Detector:
http://groups.google.com/group/relacy/files

Dmitriy V''jukov


8月26日,10:38 * pm,Dmitriy V''jukov < dvyu ... @ gmail.comwrote:
On Aug 26, 10:38*pm, "Dmitriy V''jukov" <dvyu...@gmail.comwrote:

该版本的主要功能是支持Java / CLI(又名.NET)

算法验证(但不要混淆 - 它仍然是C ++

库)。

支持包括以下内容:

* - 对GC的仿真:只是分配 - 忘记。 GC消除了与无锁算法相关的重要问题 - 安全内存
回收和ABA问题。您可以使用GC并在C ++模式下 - 只需

定义RL_GC。

* - CLI内存模型。更强大的原子RMW操作和更强大的

seq_cst围栏。

* - Java内存模型。更强大的原子RMW操作和更强大的

seq_cst围栏和seq_cst围栏在易失性

存储和易失性负载之间自动发出。

* - 基本CLI API关联同步。 rl :: nvolatile<>

类模拟CLI挥发性。 rl :: nvar<模拟普通的CLI变量。

rl :: Interlocked命名空间中可用的互锁操作(即

rl :: Interlocked :: CompareExchange())。还有

rl :: Thread :: MemoryBarrier(),rl :: Thread :: VolatileRead(),

rl :: Thread :: VolatileWrite()和rl: :Thread :: SpinWait()。

* - 与sycnronization相关的基本Java API。 rl :: jvolatile<>,

rl :: jvar<> ;, rl :: AtomicInteger和rl :: AtomicLong。请注意,不会模拟大量的

Java / CLI支持库(各种ConcurrentQueue的

等)。但您可以使用互斥锁,condition_variables,信号量

以及来自C ++ API,POSIX API或Win API的事件。
The main feature of the release is support for Java/CLI (aka .NET)
algorithm verification (but don''t get confused - it''s still C++
library).
The support includes following things:
*- Emulation of GC: just allocate-and-forget. GC eliminates important
problems associated with lock-free algorithms - safe memory
reclamation and ABA problem. You can use GC and in C++ mode - just
define RL_GC.
*- CLI memory model. Stronger atomic RMW operations and stronger
seq_cst fence.
*- Java memory model. Stronger atomic RMW operations and stronger
seq_cst fence and seq_cst fence emitted automatically between volatile
store and volatile load.
*- Basic CLI API associated with synchronization. rl::nvolatile<>
class emulates CLI volatiles. rl::nvar<emulates plain CLI variables.
Interlocked operations available in rl::Interlocked namespace (i.e.
rl::Interlocked::CompareExchange()). And also
rl::Thread::MemoryBarrier(), rl::Thread::VolatileRead(),
rl::Thread::VolatileWrite() and rl::Thread::SpinWait().
*- Basic Java API associated with sycnronization. rl::jvolatile<>,
rl::jvar<>, rl::AtomicInteger and rl::AtomicLong. Note that extensive
Java/CLI support libraries are not emulated (various ConcurrentQueue''s
and so on). But you can use mutexes, condition_variables, semaphores
and events from C++ API, POSIX API or Win API.



我忘记提及以下时刻。在Java / CLI中没有数据和/ b $ b种族和未初始化的变量。这基本上迫使我在Java / CLI模式下禁用某些类型的自动检测错误(数据,b $ b比赛和访问未初始化的变量)。并且从验证的角度来看,这是不好的
。但是在Java / CLI模式下你还可以使用rl :: var<>',这将有效地重新启用

检测上述类型的错误。即如果您知道某些

变量必须仅以单线程方式访问(例如,

所有访问都受互斥锁保护),那么您可以使用rl :: var< for

这个变量。

Dmitriy V''jukov


I forgot to mention following moment. There are no such things as data
races and uninitialized variables in Java/CLI. This basically forces
me to disable some types of automatically detectable errors (data
races and accesses to uninitialized variables) in Java/CLI mode. And
from verification point of view this is bad. But in Java/CLI mode you
still can use rl::var<>''s, and this will effectively re-enable
detection of mentioned types of errors. I.e. if you know that some
variable must be accesses only in ''single-threaded way'' (for example,
all accesses are protected by mutex), then you can use rl::var<for
this variable.
Dmitriy V''jukov


这篇关于Re:用于C ++ 0x的同步算法验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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