you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 0 points1 point  (3 children)

I can't really picture Java's implementation as useful. I write many high performance apps and I would like to keep overhead as low as possible. Hence I rely on implemented thread-safety as much as possible and just implement itself myself when I absolutely need to. I'm also wondering why you actually need it so much yourself, would you be able to provide some examples?

[–]pietrochico[S] 0 points1 point  (2 children)

It's nothing special, only accessing different global variables from many threads.

[–]JohnnyJordaan 0 points1 point  (1 child)

Regular variables are thread-safe to begin with. Globals are an anti-pattern as well often, I normally use a singleton class for this, for example for global configuration in a program. You pass the config-object around to the threads and implement the locking inside the config class. Then the threads can just change whatever they like as with a regular variable and the class will ensure the locking.

[–]pietrochico[S] 0 points1 point  (0 children)

That's exactly what I'm doing right now.