Skip to content

Fix index initialization and loop termination condition of LockFreePool's remove method #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix index initialization and loop termination condition
  • Loading branch information
nox213 committed Nov 13, 2023
commit db8a7ce42b978d6f0b9d9705edff9d98d94d9693
6 changes: 3 additions & 3 deletions src/main/scala/org/learningconcurrency/ch3/LockFreePool.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ object LockFreePool {
def remove(): Option[T] = {
val start = (Thread.currentThread.getId % buckets.length).toInt
@tailrec def scan(witness: Long): Option[T] = {
var i = (start + 1) % buckets.length
var i = start
var sum = 0L
while (i != start) {
do {
val bucket = buckets(i)

@tailrec def retry(): Option[T] = {
Expand All @@ -55,7 +55,7 @@ object LockFreePool {
}

i = (i + 1) % buckets.length
}
} while (i != start)
if (sum == witness) None
else scan(sum)
}
Expand Down