zoukankan      html  css  js  c++  java
  • Java Concurrency (1)

    Memory that can be shared betweenthreads is called shared memory or heap memory. The term variable as used inthis technical report refers to both fields and array elements. Variables thatare shared between threads are referred to as shared variables. All instance fields,static fields, and array elements are shared variables allocated in heapmemory. Local variables, formal method parameters, and exception-handlerparameters are never shared between threads and are not affected by the memorymodel.

    The visibility of writes toshared variables can be problematic because the value of a shared variable maybe cached and not written to main memory immediately. Consequently, anotherthread may read a stale value of the variable.

    A further concern is thatconcurrent executions of code are typically interleaved, and statements may bereordered b the compiler or runtime system to optimize performance. Thisresults in execution orders that are not immediately obvious when the sourcecode is examined. Failure to account for possible reordering is a common sourceof data races.

    Volatile accesses do notguarantee the atomicity of composite operations such incrementing a variable.Consequently, volatile is not applicable in cases where the atomicity ofcomposite operations must be guaranteed.

    A correctly synchronized programis one whose sequentially consistent executions do not have any data races.

    Correct visibility guaranteesthat multiple threads accessing shared data can view each others’ results, butdoes not establish the order of when each thread reads or writes the data.Correct synchronization guarantees that threads access data in a proper order.

  • 相关阅读:
    命令行界面下用户和组管理之groupadd的使用
    vue数据更新UI不刷新显示解决方案
    传入函数作为string.replace方法的第二个参数应用
    CSS 黑魔法-css控制图标颜色
    谈谈Web Components
    js函数组合
    “平滑滚动”效果骚操作
    BFC布局解析
    关于js构造函数return的一些解惑
    关于setTimeout和setInterval你不知道的事
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3187000.html
Copyright © 2011-2022 走看看