OS : FreeBSD 8.2 on Oracle VM Virtual Box
I am trying to test that a process attempting to acquire a read lock will be blocked until it is able to acquire it. After initializing rw_lock in Process #1 and locking the lock as a writer I create a second process which attempts to acquire the lock as a reader using blocking rw_rlock(). What I am shooting for is for process #2 to be blocked until process #1 releases Write lock so I am attempting to use pause to insure that process #2 has enough time to be scheduled. However this same pause somehow crashes the system in this scenario since if it is removed the program runs fine. If I replace the pause with a busy loop in Process #1, Process #2 does not get scheduled until Process #1 finishes so it ruins the point of the test. DELAY() also does not allow Process #2 to be scheduled. Any pointers would be appreciated.
Process #1:
static void test_rw_rlock(void)
{
const int seconds = 1;
rw_init(pResourceLock, "RWLock");
rw_wlock(pResourceLock);
kproc_create(&use_rw_rlock, NULL, NULL, 0, 0, "use_rw_rlock()");
pause("---", hz * seconds);
rw_wunlock(pResourceLock);
rw_destroy(pResourceLock);
}
Process #2 :
static void use_rw_rlock(void* arg)
{
rw_rlock(pResourceLock);
rw_unlock(pResourceLock);
kproc_exit(0);
}
Sleeping while hold a rw lock is a no-no.