I am implementing a wrapper around pthread_rwlock_t for iphone dev. Docs say that acquiring a read lock after acquiring a write lock is undefined. Does POSIX allow me to query whether I already have the write lock? Or, what is the best way of preventing this situation from happening?
Thanks!
Your wrapper should keep track of whether it already has the write lock held in that thread. You can do this in a number of ways, but looking at how popular libraries ilke boost or ACE do it would probably help.
You should consider using one of those existing libraries and skip the worries and effort of re-implementing what has probably been done before.