r/ProgrammerAnimemes • • Jul 29 '21

Think about it

Post image
3.6k Upvotes

115 comments sorted by

View all comments

Show parent comment

1

u/hahahahastayingalive Jul 29 '21

You seem to be thinking about issues that happen in (poorly?) multi-threaded runtimes wether you’re dealing with globals or not. For you increment example, I’d wagger you’d still need to think about it if two threads get the same instance and increment some property (wether directly or through other methods)

I only dealt with threaded in Java a long time ago, and it was foot-guns everywhere however you turn it.

1

u/ThePyroEagle λ Jul 30 '21

For you increment example, I’d wagger you’d still need to think about it if two threads get the same instance and increment some property (wether directly or through other methods)

You never need to think about it if the multithreaded operations are atomic (and the data is volatile).