volatile

Why is this simple c program with gcc (clang) inline assembly exhibiting undefined behaviour?

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to do a very simple thing with gcc assembler extension: load an unsigned int variable into a register add 1 to it output the result While compiling my solution: #include <stdio.h> #define inf_int volatile unsigned long long int main(int argc, char *argv[]){ inf_int zero = 0; inf_int one = 1; inf_int infinity = ~0; printf("value of zero, one, infinity = %llu, %llu, %llu\n", zero, one, infinity); __asm__ volatile ( "addq $1, %0" : "=r" (infinity) ); __asm__ volatile ( "addq $1, %0" : "=r" (zero) ); __asm__ volatile ( "addq $1, %0" :

C/C++: casting away volatile considered harmful?

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: (related to this question Is It Safe to Cast Away volatile? , but not quite the same, as that question relates to a specific instance) Is there ever a case where casting away volatile is not considered a dangerous practice? (one particular example: if there is a function declared void foo ( long * pl ); and I have to implement void bar ( volatile long * pl ); with part of my implementation requiring bar() to call foo(pl), then it seems like I can't get this to work as is, because the assumptions made by the compilation of foo() and

ARM Cortex-a9 event counters return 0

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm currently trying to use the event counters on an ARM Cortex-a9 (on a Xilinx zynq EPP) to count cycles. I've adapted some ARM example code from ARM for this purpose. I'm programming this bare-metal with the GNU ARM EABI compiler. The way I understand the use of the PMU is that you first have to enable the PMU. void enable_pmu (void){ asm volatile( "MRC p15, 0, r0, c9, c12, 0\n\t" "ORR r0, r0, #0x01\n\t" "MCR p15, 0, r0, c9, c12, 0\n\t" ); } then you configure the performance counter to count a certain type of event ( 0x11 for cycles in

Java volatile and cache coherence

感情迁移 提交于 2019-12-03 08:50:54
问题 If cache coherency is implemented at hardware level why do we need volatile? Any core/processor should get the latest value anyway? Or is it dealing with a different issue completely? 回答1: Cache coherence may be implemented at the processor level but, unless the processor memory model guarantees sequential consistency (which is not the case on most modern architectures), you will only get cache coherence if you ask for it. That is what volatile is for: it asks the JVM to produce the relevant

Proper use of volatile variables and synchronized blocks

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to wrap my head around thread safety in java (or in general). I have this class (which I hope complies with the definition of a POJO) which also needs to be compatible with JPA providers: public class SomeClass { private Object timestampLock = new Object(); // are "volatile"s necessary? private volatile java.sql.Timestamp timestamp; private volatile String timestampTimeZoneName; private volatile BigDecimal someValue; public ZonedDateTime getTimestamp() { // is synchronisation necessary here? is this the correct usage?

How to make /var/log persistent in Yocto Fido (poky)

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to get /var/log to be persistent in my fido build. The default setting on poky is, that there is a symlink in /var which points log -> volatile/log . volatile is a mounted on a tmpfs. So far i figured out that the symlink should be created by the base-files recipe: volatiles = "log tmp" do_install () { ... for d in ${volatiles}; do ln -sf volatile/$d ${D}${localstatedir}/$d done ... I appended the base-files recipe so the link was not created, but it still turned up in my rootfs. So where does it come from? I suspect that maybe

Does Go support volatile / non-volatile variables?

匿名 (未验证) 提交于 2019-12-03 08:35:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm new to the language so bear with me. I am curious how GO handles data storage available to threads, in the sense that non-local variables can also be non-volatile, like in Java for instance. GO has the concept of channel, which, by it's nature -- inter thread communication, means it bypasses processor cache, and reads/writes to heap directly. Also, have not found any reference to volatile in the go lang documentation. 回答1: TL;DR : Go does not have a keyword to make a variable safe for multiple goroutines to write/read it. Use the sync

long and double assignments are not atomic - How does it matter?

倖福魔咒の 提交于 2019-12-03 08:31:09
We know that long and double assignments are not atomic in Java until they are declared volatile. My question is how does it really matter in our programming practice. for instance if you the see below classes whose objects are being shared among multiple threads. /** * The below class is not thread safe. the assignments to int values would be * atomic but at the same time it not guaranteed that changes would be visible to * other threads. **/ public final class SharedInt { private int value; public void setValue(int value) { this.value = value; } public int getValue() { return this.value; } }

What Rules does compiler have to follow when dealing with volatile memory locations?

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I know when reading from a location of memory which is written to by several threads or processes the volatile keyword should be used for that location like some cases below but I want to know more about what restrictions does it really make for compiler and basically what rules does compiler have to follow when dealing with such case and is there any exceptional case where despite simultaneous access to a memory location the volatile keyword can be ignored by programmer. volatile SomeType * ptr = someAddress; void someFunc(volatile const

nvidia-smi Volatile GPU-Utilization explanation?

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I know that nvidia-smi -l 1 will give the GPU usage every one second (similarly to the following). However, I would appreciate an explanation on what Volatile GPU-Util really means. Is that the number of used SMs over total SMs, or the occupancy, or something else? +-----------------------------------------------------------------------------+ | NVIDIA - SMI 367.48 Driver Version : 367.48 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence - M | Bus - Id Disp . A | Volatile