AtomicBoolean: add compare_and_set API
还没有人认领这个 Issue。
评估
调研方向
Start by locating the AtomicBoolean implementation and its current value API. Review how the existing atomic value behavior is tested, then determine where the compare_and_set entry point belongs. Done means the proposed API supports the false-to-true use case described in the issue and its behavior is covered by the project’s tests.
由索引模型根据 Issue 内容生成。
描述
Compare-and-set is a useful functionality (that's why it exists in the Java API). It can save one from race conditions, as explained below.
Use case
- Assume an atomicboolean called
LOCKED, set to false. - Multiple concurrent threads run the following code:
if !LOCKED.value
LOCKED.value = true
# do something ....
LOCKED.value = false
end
In this scenario, concurrent threads can read a false in if !LOCKED.value, and enter the if block. That defeats the purpose of an atomicboolean-backed lock.
If there was a CAS API, the fixed code would look like this:
if LOCKED.compare_and_set(false, true)
Furthermore
Ruby has no "tryLock" either. So it's not immediately obvious how to create non-blocking synchronized code. Boolean CAS would offer a nice alternative which Java programmers (and others) already are familiar with.
What do you think?
Cheers - Victor
- 主要语言
- Ruby
- 星标
- 5.8k
- 派生
- 420
- 平均合并
- 20 小时 45 分钟
- 30 天内合并 PR
- 4
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby-concurrency/concurrent-ruby 的其他 Issue
-
难度 5/5 一周以上 新手友好度 35/100
ruby-concurrency/concurrent-ruby#1118 ·
-
难度 4/5 3-5 天 新手友好度 35/100
ruby-concurrency/concurrent-ruby#1099 · 9 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
ruby-concurrency/concurrent-ruby#1095 · 8 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
ruby-concurrency/concurrent-ruby#1093 · 3 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 45/100
ruby-concurrency/concurrent-ruby#1091 ·
查看 ruby-concurrency/concurrent-ruby 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 88/100
-
バグ
难度 1/5 1 小时以内 新手友好度 92/100
-
难度 2/5 1-3 小时 新手友好度 75/100
voxpupuli/puppet-epel#186 · 1 条评论 ·
-
external_created_at is no longer used for the message timestamp since the new message UI (v4.4.0) 未关闭Bug Frontend
难度 2/5 1-3 小时 新手友好度 78/100