I just thought about the fact that when a program within an OS, on a multi-core CPU, is requesting an mutex (e.g. for writing to HDD) this could possibly leak.
For example, this is how the mutex gets requested (pseudocode):
Code: Select all
m = getCurrentMutexState();
if( isNotUsed( m ) ){
setMutexUsed( m );
/* code here */
setMutexUnused( m );
}
tryAgain();
Code: Select all
CORE1: core1m=getCurrentMutexState(); // not in use
CORE2: core2m=getCurrentMutexState(); // not in use
CORE1: if( isNotUsed(core1m) ) // not in use, so continue
CORE2: if( isNotUsed(core2m) ) // still not set as used
CORE1: setMutexUsed( core1m ) // now it is in use
CORE2: setMutexUsed( core2m ) // it was in use, still in use
etc.
Now I was wondering how this is being solved in nowadays OS's, or how you should solve this.
Thanks,
Dennis