-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Double-checked locking *may* be broken in RequestManagerRetriever.get() #115
Comments
After reading that I'm pretty sure you're right. It should be rare, there probably isn't a lot of concurrency in most android apps since few will start loads on anything other than the main thread, but we should fix it. I agree the holder looks reasonable. |
I'm actually a bit off here, this is almost ok on Java 6+ http://en.wikipedia.org/wiki/Singleton_pattern#Lazy_initialization. In this case I'm missing volatile, but otherwise the pattern is fine. |
Looks like the developers of android consider the "double check locking" pattern is fine with volatile (SMP primer) |
Actually, I read into the next section: http://en.wikipedia.org/wiki/Singleton_pattern#Eager_initialization and my brain took a turn: I think you don't even have to be lazy here (is it premature maybe to use lazy singleton?), reasons being:
The same is not true for |
Hmm good point, lazy initialization is probably overkill, particularly since it will definitely be triggered by any Glide.load call. |
See http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
particularly the third code block and the explanation after, which is the same as
https://github.com/bumptech/glide/blob/master/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java#L37
I'm not sure if this affects Android, worth looking.
HelperHolder
looks like a clean solution for all environments.The text was updated successfully, but these errors were encountered: