On 11/28/2011 07:37 AM, breezes wrote:
Thanks. It seems that I have to write two classes, one synchronized and one is
not. Of course the
synchronized one should be the wrapper.
However, all members of a synchronized class are also shared. So I can not use
the un-synchronized class
in the synchronized wrapper class directly. I found two ways to overcome this
problem:
1. Cast away shared whenever using the wrapped un-synchronized object.
2. Define the wrapped un-synchronized object as __gshared.
Which way if more preferred?
The first one.
You manually ensure, by locking, that the object is actually unshared
during that particular time frame and that there are memory fences.
Casting away shared makes that information available to the compiler.