Immutability of string and concurrency

后端 未结 3 807
说谎
说谎 2021-01-11 21:42

Should we synchronize on writing strings? Since string is immutable we will never get inconsistent state between write and read from the 2 different threads, right?

3条回答
  •  [愿得一人]
    2021-01-11 21:52

    All functions defined on String type at language syntax level or in standard library return a new string instance. No one function mutate string in-place. Just follow this practice and you will be concurrently-safe.

提交回复
热议问题