在C11 / C ++ 11中,是否可以在同一内存上混合原子/非原子操作?(In C11/C++11, possible to mix atomic/non-atomic ops on the same memory?)
是否有可能在同一个内存位置上执行原子操作和非原子操作?
我问的不是因为我真的想这样做,而是因为我想了解C11 / C ++ 11内存模型。 他们定义了如下的“数据竞赛”:
如果一个程序的执行包含一个数据争用,如果它包含两个不同线程中的冲突动作,其中至少有一个不是原子的,而且两个都不会发生在另一个线程之前。 任何这样的数据竞争都会导致未定义的行为。 - C11§5.1.2.4p25, C ++ 11§1.10 p21
它的“至少其中之一不是原子的”部分令我感到困扰。 如果不可能混合原子操作和非原子操作,它只会说“在一个不是原子的对象上”。
我看不到在原子变量上执行非原子操作的直接方式。 C ++中的
std::atomic<T>
没有定义任何使用非原子语义的操作。 在C中,原子变量的所有直接读取/写入似乎都被转换为原子操作。我想
memcpy()
和其他直接内存操作可能是一种对原子变量执行非原子读/写的方式? 即。memcpy(&atomicvar, othermem, sizeof(atomicvar))
? 但是,这是甚至定义的行为? 在C ++中,std::atomic
是不可复制的,所以它会被定义为memcpy()
在C或C ++中的行为吗?初始化一个原子变量(无论是通过构造函数还是
atomic_init()
)都被定义为不是原子的。 但是这是一次性的操作:你不允许第二次初始化一个原子变量。 放置新的或显式的析构函数调用也可能不是原子的。 但是,在所有这些情况下,它似乎并不像定义的行为那样具有可能在未初始化值上运行的并发原子操作。对非原子变量执行原子操作看起来完全不可能:C和C ++都没有定义任何可以对非原子变量操作的原子函数。
那么这里的故事是什么? 它真的是关于
memcpy()
,或初始化/销毁,或其他?Is it possible to perform atomic and non-atomic ops on the same memory location?
I ask not because I actually want to do this, but because I'm trying to understand the C11/C++11 memory model. They define a "data race" like so:
The execution of a program contains a data race if it contains two conflicting actions in different threads, at least one of which is not atomic, and neither happens before the other. Any such data race results in undefined behavior. -- C11 §5.1.2.4 p25, C++11 § 1.10 p21
Its the "at least one of which is not atomic" part that is troubling me. If it weren't possible to mix atomic and non-atomic ops, it would just say "on an object which is not atomic."
I can't see any straightforward way of performing non-atomic operations on atomic variables.
std::atomic<T>
in C++ doesn't define any operations with non-atomic semantics. In C, all direct reads/writes of an atomic variable appear to be translated into atomic operations.I suppose
memcpy()
and other direct memory operations might be a way of performing a non-atomic read/write on an atomic variable? ie.memcpy(&atomicvar, othermem, sizeof(atomicvar))
? But is this even defined behavior? In C++,std::atomic
is not copyable, so would it be defined behavior tomemcpy()
it in C or C++?Initialization of an atomic variable (whether through a constructor or
atomic_init()
) is defined to not be atomic. But this is a one-time operation: you're not allowed to initialize an atomic variable a second time. Placement new or an explicit destructor call could would also not be atomic. But in all of these cases, it doesn't seem like it would be defined behavior anyway to have a concurrent atomic operation that might be operating on an uninitialized value.Performing atomic operations on non-atomic variables seems totally impossible: neither C nor C++ define any atomic functions that can operate on non-atomic variables.
So what is the story here? Is it really about
memcpy()
, or initialization/destruction, or something else?
原文:https://stackoverflow.com/questions/35109419
最满意答案
问题是Google希望用户自己启动任何媒体,因此如果您调试设备Chrome浏览器 ,则会在HTMLMediaElement上发出警告“ 未能执行'播放':API只能由用户的手势启动。 “这意味着你需要附加视频初始化,例如,点击事件
The problem is that Google want that users initiate by themselves any media, so If you debug your device chrome browser, you will get the warning "Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture." So that means you need to attach the video initialization, for example, with a click event
相关问答
更多-
问题是Google希望用户自己启动任何媒体,因此如果您调试设备Chrome浏览器 ,则会在HTMLMediaElement上发出警告“ 未能执行'播放':API只能由用户的手势启动。 “这意味着你需要附加视频初始化,例如,点击事件 The problem is that Google want that users initiate by themselves any media, so If you debug your device chrome browser, you will get the wa ...
-
HLS只能在Mac OS Safari 6+的桌面上使用。 看看这里供参考 。 对于桌面上的HTML5视频,您可以考虑使用MPEG DASH。 它有一个JS库 ,可以通过以下浏览器进行现场和点播: 截至2013年8月30日,Desktop Chrome,Desktop Internet Explorer 11和Mobile Chrome Beta for Android是唯一支持的浏览器。 如果您希望使用自适应流媒体技术实现更广泛的浏览器/设备覆盖范围,则需要考虑使用支持RTMP和HDS的Flash或具有S ...
-
如果来自服务器的命令正在播放,则全屏播放HTML5视频(Play HTML5 video in fullscreen if the command from server is play)[2023-05-29]
得到了我的答案, requestFullscreen()无法自动调用是出于安全原因(至少在Chrome中)。 因此它只能通过以下方式调用: 单击(按钮,链接...)键(keydown,keypress ...)HTML元素的allowfullscreen属性* * W3规范:“...为防止嵌入式内容全屏显示,只允许通过allowfullscreen属性明确允许嵌入内容HTML iframe元素将能够全屏显示。这可以防止不受信任的内容进入全屏......“ 阅读更多:全屏W3规格 Got my answer, ... -
答案很简单,移动Chrome(Android)不支持playbackRate更改,即使这个网站说它确实如此: https : //developer.mozilla.org/en/docs/Web/API/HTMLMediaElement#AutoCompatibilityTable 这是mobileRate在移动设备上更改支持的真实浏览器: Chrome 20+✔ Firefox 20 +✔ IE 9 +✔ Safari 6+✔ Opera 15+✔ 移动Chrome(Android)✖ 移动Firefo ...
-
尝试这个 var beep = new Audio('/beep.mp3'); beep.play; beep.onended = function(){ beep.remove() //Remove when played. }; 这可能有助于浏览器在完成后删除您的Beep音频对象。 如果该测试失败,尝试使用document.body.appendChild(audio);将“嘟嘟声”放入dom中document.body.appendChild(audio); It turns out - ...
-
Chrome和Firefox确实支持HTML5视频,并且视频对象代码是正确的。 因此,如果测试页不起作用,下一步是检查显示测试页的服务器是否确实支持MP4文件。 如果你使用的是Apache放在你的Directory指令中:AddType video / mp4 .mp4 如果您正在使用Windows Server,而不是编辑可以在根中创建不需要的web.config文件的站点,请将MimeType添加到服务器。 这样MP4将被应用到服务器上的所有站点:转到IIS管理器> MIME类型并添加一个新条目 .mp ...
-
首先检查您的浏览器是否支持HTML 5视频 检查浏览器是否支持视频 To get it to play on IE9, You need this full markup:
相关文章
更多- C#开发微信门户及应用(11)--微信菜单的多种表现方式介绍
- INSERT INTO blog_appitem (user_id,appid,app_secret,is_valid) VALUES (1, 'wxf415741de036114c','48e1e345fd5f11c93af18ff1714c7f78',1)
- CLR Via C# 3rd 阅读摘要 -- Chapter 21 – Automatic Memory Management (Garbage Collection)
- Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
- Jordan 11 magic reversal
- Hadoop 上使用C 语言编程
- 《C/C++图像处理编程》扫描版[PDF]
- JSTL详解之c:forEach
- C程序访问Hadoop
- 13年7月memory point
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)