Reverted changes to read/write locks & fixed original (issue was a pthread spec mismatch, pthread_rwlock_wrlock() deadlocked instead of returning EDEADLK; wrote a simple but not ideal workaround)