Switched around order of semaphores (specifically: the mutex operations should always be inside); seems to be working now