重新排序volatile字段周围的正常字段(Reorder normal field around volatile field)
基于
挥发性有什么作用? http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#incorrectlySync
和
易变的新保证 http://www.ibm.com/developerworks/library/j-jtp03304/
class VolatileExample { int x = 0; volatile boolean v = false; public void writer() { x = 42; v = true; } public void reader() { if (v == true) { //uses x - guaranteed to see 42. } } }
看起来。
1a) write to non-volatile variable x 1b) write to volatile variable v
1a永远不会移动传球1b
我想知道,如果我将源代码修改为以下内容
class VolatileExample { int x = 42; volatile boolean v = true; public void writer() { v = false; x = 0; } public void reader() { if (v == true) { //uses x - guaranteed to see 42????? } } }
是否可以置换以下序列?
2a) write to volatile variable v 2b) write to non-volatile variable x
我想知道,2b可以在2a之前移动吗? 这是因为如果2b能够在2a之前移动,读者就不能再保证在if块内看到42。
根据以下信息,我觉得2b可以在2a之前移动。
http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#reordering
写入易失性字段与监视器释放具有相同的记忆效应,从易失性字段读取具有与监视器获取相同的记忆效应。
这意味着在退出同步块之前对线程可见的任何内存操作在进入由同一监视器保护的同步块之后对任何线程都是可见的,因为所有内存操作都在发布之前发生,并且释放发生在获得。
volatile_v = true; <-- monitor release non_volatile_x = 42; (volatile_v will act as a roach motels, and it is fine for non_volatile_x to move into roach motels) non_volatile_x = 42; volatile_v = true; <-- monitor release (volatile_v will act as a roach motels, and it is not OK for non_volatile_x to move out from roach motels)
Based on
What does volatile do? http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#incorrectlySync
and
New guarantees for volatile http://www.ibm.com/developerworks/library/j-jtp03304/
class VolatileExample { int x = 0; volatile boolean v = false; public void writer() { x = 42; v = true; } public void reader() { if (v == true) { //uses x - guaranteed to see 42. } } }
It seems that.
1a) write to non-volatile variable x 1b) write to volatile variable v
1a can never moved pass 1b
I was wondering, if I modify the source code to the following
class VolatileExample { int x = 42; volatile boolean v = true; public void writer() { v = false; x = 0; } public void reader() { if (v == true) { //uses x - guaranteed to see 42????? } } }
Can the following sequence be permuted?
2a) write to volatile variable v 2b) write to non-volatile variable x
I was wondering, can 2b ever move before 2a? This is because if 2b able to move before 2a, reader can no longer guaranteed to see 42 within if block.
I feel 2b can be move before 2a based on the following information.
http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#reordering
Writing to a volatile field has the same memory effect as a monitor release, and reading from a volatile field has the same memory effect as a monitor acquire.
This means that any memory operations which were visible to a thread before exiting a synchronized block are visible to any thread after it enters a synchronized block protected by the same monitor, since all the memory operations happen before the release, and the release happens before the acquire.
and Roach Motels and The Java Memory Model
volatile_v = true; <-- monitor release non_volatile_x = 42; (volatile_v will act as a roach motels, and it is fine for non_volatile_x to move into roach motels) non_volatile_x = 42; volatile_v = true; <-- monitor release (volatile_v will act as a roach motels, and it is not OK for non_volatile_x to move out from roach motels)
原文:https://stackoverflow.com/questions/4919392
最满意答案
这个Less代码将实现您的目标:
.box-item{ &__info{ &--normal, &--left{ padding-left: 11px; padding-right: 11px; h4{ font-size: 1.5em; } } &--normal{ & .item-price{ float: right; } } } }
您无法使用双重规则
&--normal, &--left{..}
来实现最后一条规则,因为这会影响.box-item__info--left .item-price
tooThis Less code will achieve what you are looking for:
.box-item{ &__info{ &--normal, &--left{ padding-left: 11px; padding-right: 11px; h4{ font-size: 1.5em; } } &--normal{ & .item-price{ float: right; } } } }
You cannot achieve the last rule using the double rule
&--normal, &--left{..}
, because this would affect.box-item__info--left .item-price
too
相关问答
更多-
尝试 var selectors = $('[my-custom-attribute]').find('> P, > SECTION > P'); $('#one').is(selectors); $('#two').is(selectors); $('#three').is(selectors); 演示: 小提琴 Try var selectors = $('[my-custom-attribute]').find('> P, > SECTION > P'); $('#one').is(selector ...
-
CSS:之前/:选择器突然被定位在父div之后(CSS :before/:after selectors are suddenly being positioned separately of parent div)[2023-07-18]
父容器需要有position 绝对定位的元素位于“相对于其最近的定位祖先或包含块的指定位置”。 (src: MDN ) 所以,你的:after伪元素没有被其父元素包含之后,因为父元素没有被“定位”或者其位置被设置为static 。 唯一的解释是,在你之前的设置中,一定有一些东西在应用#wtf position ,这使得它的孩子可以完全置于其中。 您可以通过将位置应用于#wtf来“解决”问题, #wtf所示: #wtf { width: 10px; height: 20px; b ... -
基于你的HTML,添加background: #000到.btn-black-bg:after (两个类中的一个)就足够了,但我想你只想在同一个元素上存在两个类时才应用某些属性。 为此,您可以使用如下的父选择器: .btn { &-black-bg&-right-skew:after { background: #000; color: #fff; } } 你不能将它嵌入&-black-bg或&-black-bg &-right-skew (因为CSS的顺序 ...
-
不幸的是,你可以与选择符中的&符号结合使用 - 它需要一个类名( . ),一个id( # ),一个伪类(:)或属性选择器( [] )。 其他可接受的符号也可以与&是有效的CSS选择器组合子 , > , +和~ 。 Sass解决方案> = 3.3: 您可以对&符号#{&}使用字符串插值 ,然后将其与任何字符串连接起来。 但是,这样(如果你在嵌套规则中做到这一点)嵌套选择器仍然会自动获取在开头附加的父选择器: .parent { #{&}--at-map { ... } } 会返回: .parent .p ...
-
您可以使用此mixin作为解决方法来获得所需的结果。 @mixin child-attribute($child) { $string: inspect(&); $original: str-slice($string, 3, -4); @at-root #{ selector-replace(&, &, "[#{$original}#{$child}]" ) } { @content; } } 代码只是执行以下操作 $ string变量负责使用inspect函数将父选择器转换为字 ...
-
这个Less代码将实现您的目标: .box-item{ &__info{ &--normal, &--left{ padding-left: 11px; padding-right: 11px; h4{ font-size: 1.5em; } } &--normal{ & .item-price{ ...
-
Less允许您在父类型中使用嵌套子样式编写CSS代码。 (除了变量之外的其他东西)。 所以你不必每次都写下孩子的路径。 例如,如果你有一个类似的结构
-
'id'在HTML文档中必须是唯一的 。 您只需要将“更多”和“更少”更改为类,这样就可以绑定相同的事件处理程序并执行它们。你错过了价值周围的报价 这工作: $('option[value="d&c"]') 的jsfiddle You missed the quotes around the value This works: $('option[value="d&c"]') jsFiddle一般写下面这样的东西会被认为是不好的做法,因为它只是多余的,根本没有增值。 它只输出整个父选择器div span 。 div { span { & { padding: 1em; margin: 1em; } } } 因此,您应该避免编写仅使用 & (父选择器)的选择器。 您链接的另一个示例是一个有趣的案例,我将其称为受过教育的黑客,以解决Less中的变量范围和延迟加载概念。 假设没有父选择器(如下所示)编写相同的代码。 @unit:em; @baseval ...
相关文章
更多- Solr4.7---Field、CopyField、DynamicField
- Solr Document [null] missing required field: id 的原因
- solr required field: id
- solr error logs org.apache.solr.common.SolrException: ERROR: [doc=17] unknown field alias
- 启动Solr时报 _version_ field must exist in schema 错误的解决方法
- 一步一步掌握线程机制(三)---synchronized和volatile的使用
- elasticsearch 添加字段
- JasperReports报表字段映射
- Mysql字段操作—增加字段、删除字段、修改字段名、修改字段类型(约束条件)
- Solr boost某字段的特殊值
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。