// myMutex.c++ // $ g++ -Wall -c myMutex.c++ #include "myMutex.h" void myMutexInit(int &lock){ lock = 0; } void myMutexLock(int *lockP){ __asm__ __volatile__ ( "movl $1, %%eax \n\t" ".MyLbl1: \n\t" "lock \n\t" "xchgl %%eax, 0(%%rbx) \n\t" "cmpl $0, %%eax \n\t" "jne .MyLbl1 \n\t" : :"b"(lockP) :"%eax" ); } void myMutexUnlock(int &lock){ lock = 0; }