-
Notifications
You must be signed in to change notification settings - Fork 51
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
Move close operation out of synchronized block #48
base: master
Are you sure you want to change the base?
Conversation
This change may enhance performance if close operation take a long time
Before merging this, can you take a look at #47 - Specifically how to handle the case where an exception is thrown in one of the threads and then what should happen when another thread tries to access the resource. |
case None => | ||
throw new IllegalStateException | ||
} | ||
} | ||
if (newValue.isEmpty) { | ||
implicitly[Resource[A]].close(r) |
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.
This could be called multiple times, which I think is unsafe, concurrency-wise
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.
But it will never be called multiple times for the same r
instance
The more I think about it the more I'm hesitant on multi-threading features without more multi-threaded controls, especially if we don't know whether theunderlying resource is "concurrency safe" |
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.
Considering the complexity and not obvious improvement, I would close this for now.
if (oldReferenceCount == 1) { | ||
implicitly[Resource[A]].close(sc) | ||
sharedReference = None | ||
val newValue = if (oldReferenceCount == 1) { |
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.
Shadow newValue
This change may enhance performance if close operation take a long time