[concurrency-interest] when is safe publication safe?

Jochen Theodorou blackdrag at gmx.org
Sat Apr 24 08:39:51 EDT 2010


David Holmes wrote:
[...]
>> And finally I did read here about Fences. Would they help making my safe
>> publication possible?
> 
> Probably/possibly ... but that's the thing about Fences, trying to figure
> out exactly what they do for you. ;-) Someone else may have a more helpful
> answer on Fences.

I should maybe mention what I want this for. In the Groovy programming 
language, which I have the pleasure to help develop we have a lot of 
runtime data, that is of course shared between threads. But the current 
ways of synchronization do cost a lot of performance and since 
performance of the language is an important point, we have to draw from 
all registers to make it somehow more fast. I made several experiments 
and always come to the conclusion this and that won't work if my 
understanding of the Java Memory Model is right. I come to the 
conclusion that if it were possible to create an object in Thread t1 and 
"write that main memory", so that Thread t2 will eventually see the 
fully initialized object and some point in the future without having to 
go through memory barriers, then I will get more speed out of the 
language. The problem is that I have mutable objects I need to publish, 
so the point of being fully initialized is important to me. That t2 may 
not see the object unless some memory barrier is used is ok for me too. 
If the Groovy programmer wants it being visible, he can ensure with 
memory barriers it is going to be so.

Currently Groovy is unable to make a simple method invocation without 
passing several memory barriers. And since it is for each method 
invocation you can maybe imagine how bad this can turn out.

My current take is that with what Java (API and language) offers, it is 
impossible. So I was kind of hoping that either someone could tell me 
how to make it right or if some people are working on something to make 
  it possible.

If it is not on the scope of anyone I will have to think if I can use 
native code to achieve that.

bye blackdrag

-- 
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/



More information about the Concurrency-interest mailing list