Primitive synchronization primitives — safe?

后端 未结 5 1973
孤城傲影
孤城傲影 2020-12-21 04:05

On constrained devices, I often find myself \"faking\" locks between 2 threads with 2 bools. Each is only read by one thread, and only written by the other. Here\'s what I m

5条回答
  •  臣服心动
    2020-12-21 04:46

    Unless you understand the memory architecture of your device in detail, as well as the code generated by your compiler, this code is not safe.

    Just because it seems that it would work, doesn't mean that it will. "Constrained" devices, like the unconstrained type, are getting more and more powerful. I wouldn't bet against finding a dual-core CPU in a cell phone, for instance. That means I wouldn't bet that the above code would work.

提交回复
热议问题