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
Concurrent posible problem in function get-proc #7
Comments
Thanks for catching this race condition & providing such a helpful reproducing example. There are two ways I'm inclined to solve this. The first is a variant of your proposal, just a little more idiomatic: use (def ^:private proc
(delay (Processor. false)))
(defn get-proc []
(force proc)) This is a variant of your proposal because Delay objects get dereferenced through a call to a synchronized method, so calling The second way to solve this is not to attempt lazy initialization at all. Doing so was probably premature optimization. Can I ask, do you happen to favor one or the other? |
I would go for just using defonce and omitting the laziness after all, you On Tuesday, April 8, 2014, Perry Trolard notifications@github.com wrote:
[image: fgerard.jpg] |
I think I am having a memory leak an testing the usage of get-proc I think it should use "locking" like so:
This is because in a very heavy threading environment this can happen (example):
; you will see that f1 is invoked 3 times!
Best regards and thank you for this very helpful library.
Saludos
The text was updated successfully, but these errors were encountered: