FunnyGuy9796 wrote:
However, any implementation of a mutex simply tells the CPU to pause and I was wondering if this would be correct.
It tells the CPU to pause
while another CPU holds the lock. This is the correct behavior when the lock will be held by another CPU for only a short period of time, since there's nothing useful the current CPU can do while it waits for the other CPU to release the lock.
In systems where there is only one CPU, or systems where the lock is likely to be held for a long time, you might instead choose to yield the current time slice while waiting for the lock to be released.
FunnyGuy9796 wrote:
Example Code:
That example code is old and bad. You should use stdatomic.h (in C) or std::atomic (in C++) to implement your mutex. In fact, how about I fix that on the wiki...