X
xmarlawx
Chris Thomasson wrote:
[SNIP-quote]
Sorry I don't understand.I don't know what is a memory barrier.
Will look now.
By putting all volatile i only mean the three variables used
(flag[0],flag[1],turn)
An other thing is that i'm not using simple variable type such as int
and boolean but i'm using those
wrapped in a class i've wrote with accessor methods (without
synchronized methods).
When you say to put it in a synch block do you mean nesting the two
variables check (the spinlock),
or you mean simply the operation on the variables such as writing ?
Both ?
Right now i'm making some experiments ( i can upload the code) and
works with volatile.
Without volatile seemed to work too, but i guess that is not garanteed.
Probably (surely?) it will work as well with synchronized blocks or
methods.
[SNIP-quote]
Making everything volatile will generated a boat load of memory barriers.
Remember, the Java memory model is basically like this: [SNIP-code]
Those barriers will be executed every time you load/store into a volatile
variable. Keep that in mind. Go with Patricia's advice and just use a normal
mutex (e.g., sync block). You will use far fewer barriers that way... IMHO,
volatile on Java is way too strict IMHO. The granularity is very, very poor.
Java doesn't support loads with data-dependencies, or naked atomic
loads/stores... Or, many other types of fine-grain memory barriers..
Sorry I don't understand.I don't know what is a memory barrier.
Will look now.
By putting all volatile i only mean the three variables used
(flag[0],flag[1],turn)
An other thing is that i'm not using simple variable type such as int
and boolean but i'm using those
wrapped in a class i've wrote with accessor methods (without
synchronized methods).
When you say to put it in a synch block do you mean nesting the two
variables check (the spinlock),
or you mean simply the operation on the variables such as writing ?
Both ?
Right now i'm making some experiments ( i can upload the code) and
works with volatile.
Without volatile seemed to work too, but i guess that is not garanteed.
Probably (surely?) it will work as well with synchronized blocks or
methods.