'Is it necessary to lock a variable when reading it in different threads?

Please tell me if it is necessary to block data in a multithreaded program if :

  1. I want to read the same variable in two threads, but not change it.
  2. I want to ALWAYS read in the first stream, and change in the second. Thank you very much!


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source