[concurrency-interest] memory barriers

Kasper Nielsen news@kav.dk
Thu, 29 Jan 2004 10:30:21 +0100


Hi,

I was wondering if there exist some documents about exactly when an 
memory barrier is performed.

For example by reading http://gee.cs.oswego.edu/dl/cpj/jmm.html
---
  A writing thread releases a synchronization lock and a reading thread 
subsequently acquires that _same_ synchronization lock.
---
One get the impression that the following will not work

class foo
   int i=4
   fooHelper helper
   foo()
   {
     i=5
     synchronized(this){}
     helper.print()
   }

class fooHelper
   print(foo)
      synchronized(this)
      print(foo.i) //might read 4??


One really neat feature would be if ThreadGroup (and Thread) had a
(blocking) memorybarrier() method.
so when you did baseThreadGroup.memorybarrier you could rest assure that 
all threads had fresh data.

- Kasper