AtomicBoolean: add compare_and_set API
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Ruby
- Stars
- 5.8k
- Forks
- 420
- Avg merge
- 20h 45m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby-concurrency/concurrent-ruby
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
ruby-concurrency/concurrent-ruby#1118 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-concurrency/concurrent-ruby#1099 · 9 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
ruby-concurrency/concurrent-ruby#1095 · 8 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-concurrency/concurrent-ruby#1093 · 3 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
ruby-concurrency/concurrent-ruby#1091 ·
All issues in ruby-concurrency/concurrent-ruby
Similar issues
-
バグ
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
voxpupuli/puppet-epel#186 · 1 comment ·
-
external_created_at is no longer used for the message timestamp since the new message UI (v4.4.0) OpenBug Frontend
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
TheOdinProject/curriculum#31402 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100