Question regarding thread safety
Is it safe to call code on the foo object from multiple threads in this scenario? Like what happens if two threads try to access the foo object to call DoSomething() on instanceA at the same time?
7 Replies
it will still execute from multiple threads, i believe.
if there are parts of the method you dont want to be executed in multiple threads, you can use lock
it is safe unless you don't use shared data (in case if both threads used it for reading, it's fine)
Could you elaborate a little what you mean? I know the code going on in DoSomething is thread safe im just worried if the foo object is going to cause any issues executing it
I mean that executing
DoSomething
is thread safe it doesn't matter in which instance it's called. Unless you have shared state that any thread can interruptso if i was to spin up two threads i could call foo.instanceA.DoSomething() from both the threads?
yes, you can
Alright thank you very much
so I guess calling a method on object references is just a read operation?