static-scoped functions highlight unchecked pthread_create problem

Jim Meyering jim at meyering.net
Tue Oct 5 17:23:06 UTC 2010


Jeff Darcy wrote:

> On 10/05/2010 04:03 AM, Jim Meyering wrote:
>> Now that I've static-scoped another batch of functions,
>> I'm seeing this new warning:
>>
>>   proxy.c: In function 'repl_worker':
>>   proxy.c:796: warning: no return statement in function returning non-void [-Wreturn-type]
>>
>> repl_worker is returning void* because that's the signature
>> it must have, since it's used here:
>>
>>     pthread_create(&tid,NULL,repl_worker,NULL);
>>
>> pthread_create itself uses the return value from that start_routine
>> function if ever it returns.  Since repl_worker never returned,
>> of course, it didn't have a return statement.  However, it made
>> system calls that could fail.  In this case, it must return,
>> to indicate their failure.  If pthread_create is failing because there
>> is too little free memory or no free process table slot, then it would
>> obviously be better not to infloop here.
>
> I would have NAKed if I'd been given a chance, since the removal of the
> "item" thread parameter was causing iwhd to segfault any time
> replication is attempted.  I'll roll the fix for the "fix" into the
> coming-soon new version of my replication-test patch.

Sorry about that.
Please do not mix bug fixes and feature/test additions in the same commit.
I'll push the following fix as soon as you ACK.

>From e83a784063095074f79d532dd6c968f8b31ef72b Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Tue, 5 Oct 2010 19:21:46 +0200
Subject: [PATCH] fix bug just introduced in repl_worker

* proxy.c (repl_worker): Don't omit "item" parameter in
call to pthread_create.  Introduced by me in commit aeb23797.
Spotted by Jeff Darcy.
---
 proxy.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/proxy.c b/proxy.c
index fa25e54..cdcea5f 100644
--- a/proxy.c
+++ b/proxy.c
@@ -745,9 +745,9 @@ repl_worker_bcreate (repl_item *item)
 }

 /* Use this to diagnose failed thread creation.  */
-#define xpthread_create(thread, start_routine, msg)			\
+#define xpthread_create(thread, start_routine, item, msg)		\
   do {									\
-    int err = pthread_create (thread, NULL, start_routine, NULL);	\
+    int err = pthread_create (thread, NULL, start_routine, item);	\
     if (err) {								\
       error (0, err, msg);						\
       return NULL;							\
@@ -777,9 +777,10 @@ repl_worker (void *notused ATTRIBUTE_UNUSED)
 				xpthread_create(&prod, (proxy_host
 							? proxy_repl_prod
 							: proxy_repl_prod_fs),
-					      "failed to start producer thread");
-				xpthread_create(&cons,proxy_repl_cons,
-					      "failed to start consumer thread");
+						item,
+					    "failed to start producer thread");
+				xpthread_create(&cons,proxy_repl_cons,item,
+					    "failed to start consumer thread");
 				pthread_join(prod,NULL);
 				pthread_join(cons,NULL);
 			}
--
1.7.3.1.45.g9855b


More information about the iwhd-devel mailing list