ChinaUnix.net
相关文章推荐:

const volatile

请问这几个关键字是C++特有的码?C语言本身有没有这3个关键字!

by frankytf - C/C++ - 2005-12-29 20:11:03 阅读(901) 回复(1)

相关讨论

C++程式设计过程中,const的使用可以频度是非常高的.它在保证程式安全方面起到了不可估量的作用. 用一句话来表达最确切不过了:”小兵立大功”. 有了const,那么mutable当然缺不了. 然作为const的同胞兄弟,volatile却在很多人的视野中消失.其实volatile担负的责任有何尝小呢? 自然,它们的用法多样而灵巧,以至新手迷惑久久,下面就来系统的探讨总结一下吧: 一.一般应用 1.const修饰各种变量的用法. a.取代define #d...

by doublefox - C/C++ - 2004-10-22 14:50:59 阅读(1210) 回复(1)

在多线程的环境下,每个线程尤其在多处理机系统里可能会保留一些变量的本地复本,编译器可能优化代码使得各线程的复本不能同步得到更新,而使用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)

有如下类 class String {public: String(const char *initValue = ""); String(const String &rhs); ~String(); String& operator=(const String &rhs); const char& operator[](int index) const; char& operator[](int index);......}; 和如下语句 String s; .. ... cout <

by blizzard213 - C/C++ - 2008-07-17 19:17:34 阅读(2256) 回复(8)

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 阅读(1429) 回复(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 阅读(744) 回复(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 阅读(590) 回复(0)