You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Aaron Bannert <aa...@ebuilt.com> on 2001/07/23 08:21:01 UTC
[PATCH] update testthread.c
On Sat, Jul 21, 2001 at 09:09:32AM -0700, Ryan Bloom wrote:
>
> > > Changed the worker routine's signature to take a single parameter:
> > > apr_thread_param_t, which contains the opaque data and the apr_thread_t.
> >
> > Can we simply hide the details, and use our own _thread_main starting
> > point? Put the thread start function ptr in this structure as well, have
> > our _thread_main unwrap whatever is required (and it can create
> > thread-local data, if we ever implement that), finally calling out to the
> > user's *func?
> >
> > > httpd-2.0 will have to be updated after applying this patch to APR.
> >
> > Not if we hide this detail, I believe. I don't know what that does about
> > providing access to the apr_thread_t in the child thread. Perhaps we
> > declare the user's func as accepting arguments (apr_thread_t *me, void
> > *mine).
>
> That was where Aaron started, and I asked him to change it to this model.
> This model is more extensible moving forward IMHO.
At this point for the sake of extensibility I agree.
I've attached an additional update for testthread.c to bring it up to date
with the new thread API. I've added a new test to check that the return
value from apr_thread_exit() is making it back to apr_thread_join()
properly -- it currently doesn't. Expect this test to fail until
apr_thread_join() is fixed (patch to come shortly).
-aaron
Index: srclib/apr/test/testthread.c
===================================================================
RCS file: /home/cvspublic/apr/test/testthread.c,v
retrieving revision 1.17
diff -u -r1.17 testthread.c
--- srclib/apr/test/testthread.c 2001/03/14 15:56:44 1.17
+++ srclib/apr/test/testthread.c 2001/07/23 06:17:02
@@ -58,6 +58,7 @@
#include "apr_general.h"
#include "errno.h"
#include <stdio.h>
+#include <stdlib.h>
#ifdef BEOS
#include <unistd.h>
#endif
@@ -72,57 +73,66 @@
}
#else /* !APR_HAS_THREADS */
-void * APR_THREAD_FUNC thread_func1(void *data);
-void * APR_THREAD_FUNC thread_func2(void *data);
-void * APR_THREAD_FUNC thread_func3(void *data);
-void * APR_THREAD_FUNC thread_func4(void *data);
+void * APR_THREAD_FUNC thread_func1(apr_thread_param_t *thrparm);
+void * APR_THREAD_FUNC thread_func2(apr_thread_param_t *thrparm);
+void * APR_THREAD_FUNC thread_func3(apr_thread_param_t *thrparm);
+void * APR_THREAD_FUNC thread_func4(apr_thread_param_t *thrparm);
apr_lock_t *thread_lock;
apr_pool_t *context;
int x = 0;
+apr_status_t exit_ret_val = 123; /* just some made up number to check on later */
-void * APR_THREAD_FUNC thread_func1(void *data)
+void * APR_THREAD_FUNC thread_func1(apr_thread_param_t *thrparm)
{
int i;
+ apr_thread_t *thread = thrparm->t;
for (i = 0; i < 10000; i++) {
apr_lock_acquire(thread_lock);
x++;
apr_lock_release(thread_lock);
}
+ apr_thread_exit(thread, &exit_ret_val);
return NULL;
}
-void * APR_THREAD_FUNC thread_func2(void *data)
+void * APR_THREAD_FUNC thread_func2(apr_thread_param_t *thrparm)
{
int i;
+ apr_thread_t *thread = thrparm->t;
for (i = 0; i < 10000; i++) {
apr_lock_acquire(thread_lock);
x++;
apr_lock_release(thread_lock);
}
+ apr_thread_exit(thread, &exit_ret_val);
return NULL;
}
-void * APR_THREAD_FUNC thread_func3(void *data)
+void * APR_THREAD_FUNC thread_func3(apr_thread_param_t *thrparm)
{
int i;
+ apr_thread_t *thread = thrparm->t;
for (i = 0; i < 10000; i++) {
apr_lock_acquire(thread_lock);
x++;
apr_lock_release(thread_lock);
}
+ apr_thread_exit(thread, &exit_ret_val);
return NULL;
}
-void * APR_THREAD_FUNC thread_func4(void *data)
+void * APR_THREAD_FUNC thread_func4(apr_thread_param_t *thrparm)
{
int i;
+ apr_thread_t *thread = thrparm->t;
for (i = 0; i < 10000; i++) {
apr_lock_acquire(thread_lock);
x++;
apr_lock_release(thread_lock);
}
+ apr_thread_exit(thread, &exit_ret_val);
return NULL;
}
@@ -172,7 +182,15 @@
apr_thread_join(&s2, t2);
apr_thread_join(&s3, t3);
apr_thread_join(&s4, t4);
- fprintf (stdout, "OK\n");
+ fprintf (stdout, "OK\n");
+
+ fprintf(stdout, "Checking thread's returned value.......");
+ if (s1 != exit_ret_val || s2 != exit_ret_val ||
+ s3 != exit_ret_val || s4 != exit_ret_val) {
+ fprintf(stderr, "Invalid return value (not expected value)\n");
+ exit(-1);
+ }
+ fprintf(stdout, "OK\n");
fprintf(stdout, "Checking if locks worked.......");
if (x != 40000) {