-
Notifications
You must be signed in to change notification settings - Fork 105
Answer to Exercise 6 of Chapter 7 #32
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
Answer to Exercise 6 of Chapter 7 #32
Conversation
@annotation.tailrec | ||
final def +=(elem: T): this.type = { | ||
val ts = buf.single() | ||
if (buf.single.compareAndSet(ts, ts :+ elem)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are using STM, you can wrap the two calls into an atomic
block, and then you don't need retries if CAS
fails. STM should be doing the retries for you.
It is certainly useful to have a |
@axel22 Thanks for review! |
@axel22 I renamed |
Great - thanks a lot! |
Thanks for merging 😄 |
@axel22 Please review.