Volatile variables can also be used to store shared variables at a lower cost than that of synchronization , but they have limitations 还可以使用可变变量来以比同步更低的成本存储共享变量,但它们有局限性。
A shared variable or event is stored in memory only once , no matter how many or few instances you create of its class or structure 共享变量或事件只能在内存中存储一次,而无论您创建多少个它的类或结构的实例。
Unfortunately , this situation is a common use case for volatile - using a volatile field as a " guard " to indicate that a set of shared variables had been initialized 不幸地,这是volatile常见用例用一个volatile字段作为“守护”表明已经初始化了一组共享变量。
In particular , nearly every modern processor has instructions for updating shared variables in a way that can either detect or prevent concurrent access from other processors 特别是,几乎每个现代处理器都有通过可以检测或阻止其他处理器的并发访问的方式来更新共享变量的指令。
Developers may find use for atomic variables directly as a higher - performance replacement for shared counters , sequence number generators , and other independent shared variables that otherwise would have to be protected by synchronization 开发人员可以直接将原子变量用作共享计数器、序号生成器和其他独立共享变量的高性能替代,否则必须通过同步保护这些变量。
Shared Variables are a feature of the APL language which allowed mainframe APL programs to communicate with other facilities on a computer, which could include external files, DBMS, or other users. Shared Variables were first introduced by IBM in their APL.