volatile

When to use volatile with register/local variables

吃可爱长大的小学妹 提交于 2019-12-12 19:03:14
问题 What is the meaning of declaring register arrays in CUDA with volatile qualifier? When I tried with volatile keyword with a register array, it removed the number of spilled register memory to local memory. (i.e. Force the CUDA to use registers instead of local memory) Is this the intended behavior? I did not find any information about the usage of volatile with regard to register arrays in CUDA documentation. Here is the ptxas -v output for both versions With volatile qualifier __volatile__

Where all to use volatile keyword in C

大憨熊 提交于 2019-12-12 16:24:42
问题 I know volatile keyword prevents compiler from optimizing a variable and read it from memory whenever it is read. Apart from memory mapped registers, what are all the situations where we need to use volatile? Given a conforming compiler, do I have to declare test_var as volatile in both scenarios? 1. In file1.c int test_var=100; void func1() { test_var++; } In file2.c extern int test_var; void func2() { if(test_var==100) { .... } } 2. In file1.c int test_var=100; void func1() { } In file2.c

Display difference between volatile and usual variable in Java

流过昼夜 提交于 2019-12-12 14:20:45
问题 I am trying to create an example to display the difference between volatile and usual variables like: package main; public class TestVolatile extends Thread { public int l = 5; public volatile int m = -1; public TestVolatile(String str) { super(str); } public void run() { int i = 0; while ((l > 1) && (l < 10)) { if (m >= 0) { m++; } i++; l = 5; System.out.println("5=" + i + " m=" + m); } } public static void main(String[] args) throws InterruptedException { TestVolatile tva = new TestVolatile

Can a C++ Compiler Eliminate a Volatile Local Var that is not Read

核能气质少年 提交于 2019-12-12 11:30:32
问题 Say, I have this code: int f() { volatile int c; c=34; return abc(); } The volatile int c is never read. But it is marked as volatile , can the compiler eliminate it altogether? My testing in Visual C++ 2010 shows contradictory results. In VC++, if I enable optimization (maximizing speed) the above function contains a local variable called c (by looking at the generated assembly listing). But, instead of using assignment operator, I also tried to initialize the variable by a compiler

Is `memcpy((void *)dest, src, n)` with a `volatile` array safe?

烈酒焚心 提交于 2019-12-12 07:26:47
问题 I have a buffer that I use for UART, which is declared this way: union Eusart_Buff { uint8_t b8[16]; uint16_t b9[16]; }; struct Eusart_Msg { uint8_t msg_posn; uint8_t msg_len; union Eusart_Buff buff; }; struct Eusart { struct Eusart_Msg tx; struct Eusart_Msg rx; }; extern volatile struct Eusart eusart; And here is the function that fills the buffer (which will be sent using interrupts): void eusart_msg_transmit (uint8_t n, void *msg) { if (!n) return; /* * The end of the previous transmission

Shared enum between multiple threads

佐手、 提交于 2019-12-12 04:49:22
问题 I have an enumeration that is shared between multiple threads: public enum Action { Read, Write, None } Within a class I have a variable of Action type: public Action _action; This is a shared variable, that is, it is updated and read from multiple threads. For example, from one thread I do: _action = Action.Read And from another one: if (_action == Action.Read) { } else if (_action == Action.Write) { } else if (_Action == Action.None) { } else { } So I would like to use Interlock to update

A little clarification on the volatile keyword

霸气de小男生 提交于 2019-12-12 03:47:58
问题 Consider the snippet from Java Concurrency in Practice- // Unsafe publication public Holder holder; public void initialize(){ holder = new holder(42); } public class Holder{ private int n; public Holder(int n) { this.n = n; } public void assertSanity(){ if (n != n) throw new AssertionError("This statement is false."); } } One of the solutions suggested by the author of the book is - public static Holder holder = new Holder(42); And if the only requirement was to prevent the AssertionError ,

Doubts related to volatile , immutable objects, and their use to acheive synchronization

五迷三道 提交于 2019-12-11 18:59:17
问题 I was reading book "java concurrency in practice" and end up with some doubts after few pages. 1) Voltile with non premitive data types : private volatile Student s; what is significance of volatile when it comes with non premitive data types ? (I think in this case only think that is sure to be visible to all threads is what Strudent object s is pointing currently and it is possible one thread A modifies some internal member of student and that is not visible to other threads. Am I right ??)

你真的了解JMM吗?

谁都会走 提交于 2019-12-11 14:03:43
引言 在现代计算机中,cpu的指令速度远超内存的存取速度,由于计算机的存储设备与处理器的运算速度有几个数量级的差距,所以现代计算机系统都不得不加入一层读写速度尽可能接近处理器运算速度的高速缓存(Cache)来作为内存与处理器之间的缓冲:将运算需要使用到的数据复制到缓存中,让运算能快速进行,当运算结束后再从缓存同步回内存之中,这样处理器就无须等待缓慢的内存读写了。 基于高速缓存的存储交互很好地解决了处理器与内存的速度矛盾,但是也为计算机系统带来更高的复杂度,因为它引入了一个新的问题:缓存一致性(Cache Coherence)。在多处理器系统中,每个处理器都有自己的高速缓存,而它们又共享同一主内存(MainMemory)。当多个处理器的运算任务都涉及同一块主内存区域时,将可能导致各自的缓存数据不一致,举例说明变量在多个CPU之间的共享。如果真的发生这种情况,那同步回到主内存时以谁的缓存数据为准呢?为了解决一致性的问题,需要各个处理器访问缓存时都遵循一些协议,在读写时要根据协议来进行操作,这类协议有MSI、MESI(Illinois Protocol)、MOSI、Synapse、Firefly及Dragon Protocol等。 一、JMM(Java Memory Model) java虚拟机规范定义java内存模型屏蔽掉各种硬件和操作系统的内存访问差异

Why is the planner coming up with different results for functions with different volatilities?

北城以北 提交于 2019-12-11 09:39:40
问题 This question comes as a follow up to and a result of SQL function very slow compared to query without function wrapper. I should note that I don't consider this a duplicate, since that question was asking for a solution to a specific problem. I am asking for more information about the behavior in general here, and demonstrating how it can be reproduced. (To demonstrate the difference, you can see a fairly long comment thread on the accepted answer where we discussed the behavior, and I felt