Currently this seems to be working but maybe one day it’ll bug :
I have a 2 dimensional array of boolean, those boolean represent the state of various objects (if they are ready or not to be processed)
A thread is running and making those objects, once an object is made it’s boolean is set to “true” (making an object takes up to 20ms).
my question is :
Can I read (only read) this array while the thread is doing its magic?
What would happend if the thread was to write true while my method was reading it?
thanks.
Writes to
booleanare atomic so you won’t see any inconsistencies. This is not the case forlonganddouble.The worst thing than can happen to you is visibility. Visibility problems occur when one thread updated given variable but other threads don’t see that change immediately (or never).
In order to make sure all threads see the same, most up-to-date value, you must use some sort of synchronization or
volatilefields.