7 ms·
> From the point of view of the software, running a bunch of instructions in sequence, you do get stale values. You can have two threads wait for a signal, then
by vmfunction 3y ago
> From the point of view of the software, running a bunch of instructions in sequence, you do get stale values. You can have two threads wait for a signal, then both read a value, and both get different results. You can have a thread set a flag after it's done editing some values, have another thread wait for the flag, and then after waiting it sees the edits as still incomplete.
Isn't that implementation of semaphore? I would imagine that should already being done in the CPU implementation?
- pjc50 3y agoOnly if you use the special instructions for that purpose. If you're just doing a regular read/write, you're vulnerable to this kind of problem. If you do use the atomic instructions, you're guaranteed a consistent view across threads for that location. Check your platform documentation as to whether this is also a memory barrier, affecting ordering between the atomic instruction and other non-atomic instructions.