Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# .Net 4.5 Multithreading sharing variables

I am new to multithreading and have a question on sharing objects. I am doing this in C# .Net 4.5

I have an list that contains a object called Price. The class Price contains 12 properties one of type datetime and the others are of type double.

I then run 4 tasks which all reference this object List. None of the tasks will change the List object they are just reading from the object.

So the fact the tasks are all referencing the same object but only reading from it am I right to think that I will not need any locking?

like image 634
mHelpMe Avatar asked Feb 15 '23 15:02

mHelpMe


1 Answers

Yes the read does not modify anything for those types (and indeed most types), so it's safe.

like image 116
David S. Avatar answered Feb 28 '23 11:02

David S.