On Mon, Oct 12, 2009 at 10:15 PM, Oleg G. <ojo...@gmail.com> wrote:

>
> After reading Naftoli's post i checked the way inner object laziness
> is implemented. And it appears to be not thread safe.
>

It is not threadsafe.  This is a known defect and is supposed to be
addressed in 2.8.  But, the cost of a failure is dual initialization of the
field.


> Following code:
>
> class A { val a = 1 }
> class B { object b extends A }
>
> Generates getter for b as follows:
>
> public final B$b$ b();
>  Code:
>   0:   aload_0
>   1:   getfield        #18; //Field b$module:LB$b$;
>   4:   ifnonnull       19
>   7:   aload_0
>   8:   new     #20; //class B$b$
>   11:  dup
>   12:  aload_0
>   13:  invokespecial   #23; //Method B$b$."<init>":(LB;)V
>   16:  putfield        #18; //Field b$module:LB$b$;
>   19:  aload_0
>   20:  getfield        #18; //Field b$module:LB$b$;
>   23:  areturn
>
> Looks like its not synchronized? I also looked at lazy vals generated
> code (when i was thinking on val based Records) and dropped the idea
> because of synchronization for every single access to a field.
>

That's not the case.  There's only a synchronization if the initial
non-synchronized test fails.


> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to