Post by Paul ThomasDoes anyone know of a way to find which pthread currently has the lock
of a mutex? It doesn't have to be portable - maybe linux or some other
platform specific.
On solaris, dbx can do that:
(dbx) sync -info 0xff369b80
__uberdata+0xfc0 (0xff369b80): usync_? mutex(unlocked)
Lock is unowned
No threads are blocked by this lock
Post by Paul ThomasI only want to assert() that a lock is held by the caller so even if it
only works on one platform it's better than nothing.
Ah, you want a programmatic way ...
Post by Paul ThomasWhy don't you use PTHREAD_MUTEX_ERRORCHECK as mutex type?
That way, when you attempt to lock/unlock a mutex you will automatically
get an error return which will tell you what's up.
I think he wants to assert that his caller has a particular lock
held:
int somefunc(..., pthread_mutex_t *mtx)
{
assert(pthread_equal(pthread_self(), mutex_owner(mtx)));
...
}
I don't see how ERRORCHECK would help him with that ...
If you always use your own lock/unlock wrapper function and
care about only one mutex, then storing lock owner in a global
variable just after pthread_mutex_lock, and clearing it just before
pthread_mutex_unlock will do the trick portably.
Otherwise, you'll have to grovel in libpthread internals (possible
on Linux and Solaris) -- the owner is (usually) stored somewhere
in the pthread_mutex_t ...
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.