Wanted to see how a mutex looks in x86 assembler. Originally wrote a C++ app, using C++11:
#include <mutex>
int main(){
std::mutex m;
volatile int i = 0;
m.lock();
i = 6;
m.unlock();
return 0;
}
but when I checked the assembly output file there was 1000+ lines of asm and I couldn't see any atomic or LOCK
instructions.
So moving on, I found this website showing how a mutex can be written in x86:
http://forum.codecall.net/topic/64301-writing-a-simple-lock-mutex-in-cassembly/
I have seen other x86 mutex implementations in white papers which seem far more complicated, (some used CMPXCHG), so I wondered if the below code contains any hidden race conditions or problems? The code seems too simple.