Multiple threads reading an object?

BlitzMax Forums/BlitzMax Programming/Multiple threads reading an object?

ima747(Posted 2010) [#1]
I know you need to prevent a thread from reading an object while it's being modified (hence the mutex locking). But can multiple threads read an object at the same time safely? i.e. can 2 threads loop through a list at the same time as long as neither of them changes anything. Doesn't seem to be crashing for me, but I don't know if it's safe moving forward or if it's just luck... the docs would imply you have to lock things to safely access them in any way.


Otus(Posted 2010) [#2]
You can safely do reads from multiple threads. If you are smart about it, you can sometimes avoid locking even in cases that require writes. Lock when unsure, though.


ima747(Posted 2010) [#3]
thanks otus, glad I'm not just getting super lucky here.


Rozek(Posted 2010) [#4]
I agree with Jan,

"reading" from memory locations is never a problem, it is "writing" to them which may cause problems (unfortunately, "writing" may often succeed and rarely fail (i.e. produce invalid results instead of crashing) which makes it difficult to isolate the problems - as these may become appearant somewhere else in the code)