ChinaUnix.net
相关文章推荐:

硬件寄存器 volatile

在多线程的环境下,每个线程尤其在多处理机系统里可能会保留一些变量的本地复本,编译器可能优化代码使得各线程的复本不能同步得到更新,而使用volatile之后,告诉编译器不做任何优化,保持各线程的本地复本同步读写操作。 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/10296/showart_1270566.html

by pianoch - Java文档中心 - 2008-09-29 17:35:21 阅读(1058) 回复(0)

相关讨论

虽然已经学了很久的c++,但是对于这个关键字的功能还没有切实的了解,能给个例子,让我清晰的看到该关键字所起的作用. 谢谢.!!!

by mingjwan - C/C++ - 2004-12-20 10:48:06 阅读(1997) 回复(3)

ava™ 语言包含两种内在的同步机制:同步块(或方法)和 volatile 变量。这两种机制的提出都是为了实现代码线程的安全性。其中 volatile 变量的同步性较差(但有时它更简单并且开销更低),而且其使用也更容易出错。在这期的 Java 理论与实践 中,Brian Goetz 将介绍几种正确使用 volatile 变量的模式,并针对其适用性限制提出一些建议。 Java 语言中的 volatile 变量可以被看作是一种 “程度较轻的 synchro...

by welkin - Java文档中心 - 2009-07-17 13:25:18 阅读(1148) 回复(0)

1. native native是方法修饰符。Native方法是由另外一种语言(如c/c++,FORTRAN,汇编)实现的本地方法。因为在外部实现了方法,所以在java代码中,就不需要声明了,有点类似于借口方法。Native可以和其他一些修饰符连用,但是abstract方法和Interface方法不能用native来修饰。 Example: 代码 public interface TestInterface { void doMethod(); } public class Test implements TestInterface { ...

by red_justice - Java文档中心 - 2009-07-10 15:42:13 阅读(1431) 回复(0)

刚才搜索出来一个关于setjmp和longjmp的小程序如下: #include #include static jmp_buf buf; int main() { // volatile int b; // 1 int b ; b =3; if(setjmp(buf)!=0) { printf("%d ", b); exit(0); } b=5; longjmp(buf , 1); } 我的平台是:fc4,大家按照下面几种编译方式,分别看看运行结果,我被搞晕了。 (1)使用volatile,编译时不管优...

by anank - C/C++ - 2008-08-26 16:52:14 阅读(2845) 回复(11)

volatile修饰的成员变量在每次被线程访问时,都强迫从共享内存中重读该成员变量的值。而且,当成员变量发生变化时,强迫线程将变化值回写到共享内存。这样在任何时刻,两个不同的线程总是看到某个成员变量的同一个值。 Java语言规范中指出:为了获得最佳速度,允许线程保存共享成员变量的私有拷贝,而且只当线程进入或者离开同步代码块时才与共享成员变量的原始值对比。 这样当多个线程同时与某个对象交互时,就必须要注意到要...

by craighit - Java文档中心 - 2007-04-15 21:34:22 阅读(745) 回复(0)

今天看ANSI_C 99的时候看到一段: Alternatively, an implementation might perform various optimizations within each translation unit, such that the actual semantics would agree with the abstract semantics only when making function calls across translation unit boundaries. In such an implementation, at the time of each function entry and function return where the calling function and the called functi...

by zzdts - C/C++ - 2007-03-30 00:17:58 阅读(1292) 回复(3)

Transient: The transient modifier applies to variables only and it is not stored as part of its object's Persistent state. These variables are not serialized. Transient instance fields are neither saved nor restored by the standard serialization . You have to handle restoring them yourself.volatile: volatile modifier tells the compiler that the variable modified by volatile can be changed un...

by aladn - Java文档中心 - 2006-12-04 14:34:14 阅读(592) 回复(0)

static volatile unsigned char arr[30]; 这样用volatile修饰数组arr, 编译 memcmp( arr, "test", 4); 语句时为何有下面警告? 怎么修饰才正确? warning: passing arg 1 of `memcmp' discards qualifiers from pointer target type 另外, volatile 可以修饰函数的返回值么? 可以的话, 怎么写? [ 本帖最后由 Pervise 于 2006-10-10 09:38 编辑 ]

by Pervise - 程序开发 - 2006-10-14 11:13:29 阅读(787) 回复(1)

[code] #include using namespace std; class A{ public: A(); volatile string s; }; int main() { A a; a.s="abc"; cout << a.s.c_str() <

by cellar - C/C++ - 2006-09-04 14:39:24 阅读(1017) 回复(2)

要是防止全局变量被随便的修改,不想用互斥锁的方式 好像还有一个关键字修饰,问一下坛子里面的大虾,要怎么弄 能不能用volatile ,对于volatile不是很理解,哪位大虾能指点一下] 谢谢了 [ 本帖最后由 foolfoolbird 于 2006-8-28 20:10 编辑 ]

by foolfoolbird - C/C++ - 2006-08-30 15:37:17 阅读(2633) 回复(13)