首页 > TAG信息列表 > memory-model

Java-监视器解锁之前发生的关系

我最近阅读了http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html,其中清楚地描述了Java内存模型的许多内在函数.一个特别的摘录引起了我的注意: The rule for a monitorexit (i.e., releasing synchronization) is that actions before the monitorexit mus

围绕写的锁是否保证可以在另一个线程中重新读取? (.Net,内存模型)

假设我有一个属性,其设置程序受锁保护,但在吸气剂周围没有任何锁,例如 private long _myField; public long MyProperty { get { return _myField; } set { lock(whatever) _myField = value; } } 除了同步写操作(而不是读操作)之外,锁(或更确切地说是Monitor.Exit)还应

Java中的原子性和内存顺序

我是Java的新手,目前正在阅读《 Java:初学者指南》第六版.我在Java的原子性和内存顺序方面遇到了一些困惑. 在本书涉及多线程的示例中,对共享资源(例如,共享变量)的并发访问不会同步,共享资源也不会被明确标记(例如,原子或易失性或类似的东西).例如,在“尝试此15-1”(第519页)中,对

c – 非平凡可复制类型的值表示

我对标准中的以下段落感兴趣(ISO / IEC 14882:2011(E)的§3.9/ 4): The object representation of an object of type T is the sequence of N unsigned char objects taken up by the object of type T, where N equals sizeof(T). The value representation of an object is the

c – 使用4个线程获取/释放语义

我目前正在阅读Anthony Williams的C Concurrency in Action.他的一个列表显示了这段代码,他声明z!= 0的断言可以触发. #include <atomic> #include <thread> #include <assert.h> std::atomic<bool> x,y; std::atomic<int> z; void write_x() { x.store(true,std::memor

c – 与`std :: mutex`同步慢于`std :: atomic(memory_order_seq_cst)`?

在互斥量上使用原子的主要原因是互斥量很昂贵,但是原子的默认内存模型是memory_order_seq_cst,这不是很贵吗? 问题:并发使用锁的程序可以和并发无锁程序一样快吗? 如果是这样,除非我想将memory_order_acq_rel用于原子,否则它可能不值得. 编辑: 我可能会遗漏一些东西,但基于锁定的速度比

哪里可以找到C 0x同步原语的好的,可靠的文档?

我在:: std :: thread和:: std :: forward等上看过文章,但我在:: std :: atomic上看不到好文章.当然有standards proposal paper,但我还没有看到任何想要使用该设施的人的好文档. 有没有?我在哪里可以找到它?解决方法:just :: thread库有不错的documentation,由Anthony Williams的作

c – 每个memory_order是什么意思?

我读了一章,我不喜欢它.我还不清楚每个内存顺序之间的差异.这是我目前的推测,我在阅读了更为简单的http://en.cppreference.com/w/cpp/atomic/memory_order之后就明白了 以下是错误的,所以不要试图从中学习 > memory_order_relaxed:当从另一个原子var中的另一个模式完成订单时,不同

java – 如何理解发生 – 在一致之前

在chapter 17 of JLS,它引入了一个概念:发生 – 在一致之前. A set of actions A is happens-before consistent if for all reads r in A, where W(r) is the write action seen by r, it is not the case that either hb(r, W(r)) or that there exists a write w in A such tha

c – 现代x86硬件不能将单个字节存储到内存中吗?

说到C的并发内存模型,Stroustrup的C编程语言,第4版,第1节. 41.2.1,说: … (like most modern hardware) the machine could not load or store anything smaller than a word. 但是,我的x86处理器,几年前,可以存储小于一个字的对象.例如: #include <iostream> int main() { c

C的宽松记忆模型中是否存在具有依赖循环的非因果行为?

假设x和y是用0初始化的原子整数. 现在,线程A运行以下代码: if (x.load(memory_order_relaxed) == 1) { y.store(1, memory_order_relaxed); } 和线程B运行此代码: if (y.load(memory_order_relaxed) == 1) { x.store(1, memory_order_relaxed); } 在C中,是否有可能达到(x

c – exchange或compare_and_exchange是否按修改顺序读取最后一个值?

我正在读安东尼威廉姆斯C++ Concurrency in Action. 在“理解轻松订购”部分,它有: There are a few additional things you can tell the man in the cubicle, such as “write down this number, and tell me what was at the bottom of the list” (exchange) and “write down

c# – 内存模型和ThreadPool

我有一个类NonVolatileTest: public class NonVolatileTest { public bool _loop = true; } 我有两个代码示例: 1: private static void Main(string[] args) { NonVolatileTest t = new NonVolatileTest(); Task.Run(() => { t._loop = false; }); while (t._l

Java内存模型操作

我试图了解Java Memory Model,但我在行动方面遇到了一些麻烦.我理解一个动作的定义为< t,k,v,u>,但我不太明白程序是如何分解为动作的,以及这些动作是如何抽象的. 我的第一个假设是行动是原子的. var1 = var2将分为两个动作 – 读取var2和写入var1,但是示例here表明var1 = var2是一