I would like to know if I need a lock for a situation of 2 threads, one reading and the other one writing to same Variable both.
For example: We have 2 Threads: A & B, Thread A reads variable x at time T and Thread B writes variable T at time T.
Should I may consider here some type of lock?
In my case I have the Main Thread an many other SubThreads. The Main Thread holds a List<myObj>
and before starting any SubThread I create instances of myObj
assigning it to the List<myObj>
and passing myObj
to the SubThread.
At determined moment the List has to be sorted depending on a value contained in myObj
, and it can perfectly happen that the List
element which is read by the Main Thread, simultaneously is written by a SubThread.
Please some suggestions.