Discussion:
[jruby-dev] How about implementing atomic memoize pattern?
Rodrigo Rosenfeld Rosas
2013-12-14 10:26:17 UTC
Permalink
Let's face it. The common "@something ||= ..." won't go anywhere even if
it's not thread-safe.

So, I was wondering if JRuby could transform something like "@a ||= b"
into something atomic by including something like a Java's
"synchronized(this){...}" around it. Of course this should work for
class variables as well except that the mutex would be around the class
instead of the instance...

Would you see any problems with such approach?

Asking Ruby users to stop using such useful pattern, specially when it's
thread-safe in MRI by accident, won't really work if you ask me. But
maybe if JRuby could guarantee such pattern is implemented as an atomic
operation it could avoid lots of race conditions...

I'm afraid about possible deadlocks but I can't think of any example
right now...

I'm not sure if this has been already considered, has it?

Cheers,
Rodrigo.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...