How Mutexes Work
How Mutexes Work
- Subject: How Mutexes Work
- From: Dave Keck <email@hidden>
- Date: Thu, 12 Feb 2009 16:34:04 -1000
Hey,
Today, for some reason or another, I've been pondering how locks work.
After locating the pthread source (in libc, available at
opensource.apple.com, for those curious) I've found the source for the
pthread_mutex_lock, in pthread_mutex.c It seems the meat of this
function are the macros 'LOCK' and 'PLOCKSTAT_MUTEX_ACQUIRE'.
The 'LOCK' macro is defined (indirectly) as _spin_lock. _spin_lock is
implemented in various places based on the architecture you're
compiling for; in my case I'm interested in i386. For that, _spin_lock
is defined as:
_OSSpinLockLock:
_spin_lock:
__spin_lock:
movl $(_COMM_PAGE_SPINLOCK_LOCK), êx
jmpl *êx
.align 2, 0x90
.globl _OSSpinLockUnlock
.globl _spin_unlock
.globl __spin_unlock
But I can't seem to find what _COMM_PAGE_SPINLOCK_LOCK is. I'm taking
a shot in the dark that it's a function address in the kernel's
address space. Is this correct? (I'm no assembly expert! :)) If so,
where is the value for _COMM_PAGE_SPINLOCK_LOCK set?
Secondly we have PLOCKSTAT_MUTEX_ACQUIRE. I can't seem to find where
it's defined either, and it seems to be the real heavy-lifter for
pthread_mutex_lock. Any ideas?
Lastly and perhaps most important, is there a good low-level OS book
that might explain the nitty gritty when it comes to locks and
everything else deep under-the-hood?
Thanks a lot!
David
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden