Aaron Bannert <[EMAIL PROTECTED]> writes:
> On Sun, Nov 17, 2002 at 12:25:46PM +0000, Philip Martin wrote:
> > $ ./testprocmutex
> > APR Proc Mutex Test
> > ==============
> >
> > Exclusive lock test
> > Initializing the lock OK
> > Starting all of the processes OK
> > Waiting for processes to exit OK
> > Locks don't appear to work! x = 15998 instead of 16000
> >
> > The test is multi-process, but the processes are single threaded. I
> > guess the problem lies somewhere in the semaphores, but I don't have
> > any experience of using those.
>
> I just ripped out that code, want to give this another try on your
> SMP Linux box?
It still fails.
As I said, I don't know much about semaphores, but I think the problem
is something to do with process exit. I changed proc_mutex.c as
follows
Index: locks/unix/proc_mutex.c
===================================================================
RCS file: /home/cvspublic/apr/locks/unix/proc_mutex.c,v
retrieving revision 1.20
diff -u -r1.20 proc_mutex.c
--- locks/unix/proc_mutex.c 18 Nov 2002 01:59:03 -0000 1.20
+++ locks/unix/proc_mutex.c 18 Nov 2002 16:19:25 -0000
@@ -892,6 +892,8 @@
APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex)
{
+ if (!mutex->curr_locked)
+ abort();
return mutex->meth->release(mutex);
}
and now the test fails like so
$ ./testprocmutex
APR Proc Mutex Test
==============
Exclusive lock test
Initializing the lock OK
Starting all of the processes OK
Waiting for processes to exit OK
Locks don't appear to work! x = 4003 instead of 16000
The test now fails nearly every time and the "x" value is much
lower. Next I changed the test code as follows
Index: testprocmutex.c
===================================================================
RCS file: /home/cvspublic/apr/test/testprocmutex.c,v
retrieving revision 1.10
diff -u -r1.10 testprocmutex.c
--- testprocmutex.c 9 Apr 2002 06:45:06 -0000 1.10
+++ testprocmutex.c 18 Nov 2002 16:23:00 -0000
@@ -85,7 +85,8 @@
apr_proc_mutex_lock(proc_lock);
if (i == MAX_ITER) {
apr_proc_mutex_unlock(proc_lock);
- exit(1);
+ apr_sleep (1000000);
+ exit(0);
}
i++;
(*x)++;
and now the test always passes. I believe this is because the loops
all reach MAX_ITER before any of the subprocesses exit, and so any
damage to the semaphore doesn't affect the "x" value.
--
Philip Martin