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/24 02:32:35 UTC
[PATCH] testthread.c updates to work with new thread API
On Mon, Jul 23, 2001 at 05:28:14PM -0700, Aaron Bannert wrote:
> This patch was tested on UNIX. For the sake of the reviewer, I will followup
> this messages with patches that update testthread.c and another that
> will implement the changes for httpd. Also, once this gets commited,
> I have a fix for apr_thread_join() that needs to get commited. :)
Like promised, here's the testthread.c patch. This patch changes
three things:
- Added #include <stdlib.h> to make -Wall happy.
- Changed the thread_func*() routines to work with the new API. (Also
added the calls to apr_thread_pool_get() to illustrate that the
pool accessors are working).
- Added a new test to check if the return value from the thread_func()
is getting passed back properly. ** This test properly detects the
fact that apr_thread_join() is broken -- subsequent patch to come :) **
-aaron
Index: test/testthread.c
===================================================================
RCS file: /home/cvspublic/apr/test/testthread.c,v
retrieving revision 1.17
diff -u -r1.17 testthread.c
--- test/testthread.c 2001/03/14 15:56:44 1.17
+++ test/testthread.c 2001/07/24 00:11:39
@@ -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_t *thd, void *data);
+void * APR_THREAD_FUNC thread_func2(apr_thread_t *thd, void *data);
+void * APR_THREAD_FUNC thread_func3(apr_thread_t *thd, void *data);
+void * APR_THREAD_FUNC thread_func4(apr_thread_t *thd, void *data);
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_t *thd, void *data)
{
int i;
+ apr_pool_t *pool = apr_thread_pool_get(thd);
for (i = 0; i < 10000; i++) {
apr_lock_acquire(thread_lock);
x++;
apr_lock_release(thread_lock);
}
+ apr_thread_exit(thd, &exit_ret_val);
return NULL;
}
-void * APR_THREAD_FUNC thread_func2(void *data)
+void * APR_THREAD_FUNC thread_func2(apr_thread_t *thd, void *data)
{
int i;
+ apr_pool_t *pool = apr_thread_pool_get(thd);
for (i = 0; i < 10000; i++) {
apr_lock_acquire(thread_lock);
x++;
apr_lock_release(thread_lock);
}
+ apr_thread_exit(thd, &exit_ret_val);
return NULL;
}
-void * APR_THREAD_FUNC thread_func3(void *data)
+void * APR_THREAD_FUNC thread_func3(apr_thread_t *thd, void *data)
{
int i;
+ apr_pool_t *pool = apr_thread_pool_get(thd);
for (i = 0; i < 10000; i++) {
apr_lock_acquire(thread_lock);
x++;
apr_lock_release(thread_lock);
}
+ apr_thread_exit(thd, &exit_ret_val);
return NULL;
}
-void * APR_THREAD_FUNC thread_func4(void *data)
+void * APR_THREAD_FUNC thread_func4(apr_thread_t *thd, void *data)
{
int i;
+ apr_pool_t *pool = apr_thread_pool_get(thd);
for (i = 0; i < 10000; i++) {
apr_lock_acquire(thread_lock);
x++;
apr_lock_release(thread_lock);
}
+ apr_thread_exit(thd, &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) {