I've heard i++ isn't thread safe, is ++i thread-safe?

后端 未结 16 1873
野性不改
野性不改 2020-11-27 10:38

I\'ve heard that i++ isn\'t a thread-safe statement since in assembly it reduces down to storing the original value as a temp somewhere, incrementing it, and then replacing

16条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 11:08

    Throw i into thread local storage; it isn't atomic, but it then doesn't matter.

提交回复
热议问题