Overhead of synchronized class used in unshared situation

Jonathan M Davis jmdavisProg at gmx.com
Sun Nov 27 21:00:13 PST 2011


On Sunday, November 27, 2011 13:53:49 breezes wrote:
> I have several cumtermized data structures which will be used both in shared
> and unshared situations. Because un-synchronized classes can not be used in
> shared situation, I think i have to define these classes as synchronized
> classes, because otherwise i will have to write the same class twice.
> However, if those classes are used in unshared situations, such as local
> variable or unshared global variable, does the overhead of synchronized
> still remain? I'm writing database in which performance is critical.

If your class is synchronized, then you get the overhead. If you really want 
to use a class both in a situation which is shared and one which is not and 
only synchronize the shared case, then you need two separate classes. An 
alternative would be to use a wrapper class which is synchronized and use the 
wrapper when you care about synchronization and not use it otherwise.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list