For a uni-processor, the lock algorithm is pretty simple.
Lock(threadID) {
Disable Interrupts
If lock is already owned by same thread{
Restore Interrupts
return
}
if lock is free {
make lock busy
set current thread as the owner of the lock
}
else {
add threadID to the lock queue.
}
Restore Interrupts
return
}
But how do we implement this code in multiprocessor/multicore systems. What if 2 cores/procs try to give the same lock to different processes.