misc/143807: pthread_create retval check fixup

pluknet pluknet at gmail.com
Thu Feb 11 17:00:02 UTC 2010


>Number:         143807
>Category:       misc
>Synopsis:       pthread_create retval check fixup
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 11 17:00:01 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     pluknet
>Release:        HEAD r203781
>Organization:
>Environment:
>Description:
I faced with incorrect return code checking in netrate's pthread_create(3) calls: pthread_create may return errcode > 0, while in netrate/ code pthread_create() checked for < 0 on error.

from pthread_create(3):
RETURN VALUES
     If successful, the pthread_create() function will return zero.  Otherwise
     an error number will be returned to indicate the error.

What's in thr_create.c:

                /*
                 * Translate EPROCLIM into well-known POSIX code EAGAIN.
                 */
                if (ret == EPROCLIM)
                        ret = EAGAIN;
[...]
        return (ret);

So.. Slightly modified code (let's call it tools/tools/netrate/juggle/juggle.c):
$ make NTHR=3000
$ ./juggle
[...]
create 2986
create 2987
create 2988
create 2989
create 2990
create 2991
create 2992
create 2993
create 2994
create 2995
create 2996
create 2997
create 2998
create 2999
^C^
[something wrong here!]

Fixed slightly modified code version:
create 1495
create 1496
create 1497
create 1498
create 1499
juggle: main: pthread_create 35: Too many processes

>How-To-Repeat:

>Fix:
Patch attached.


Patch attached with submission follows:

Index: tools/tools/netrate/http/http.c
===================================================================
--- tools/tools/netrate/http/http.c	(revision 203781)
+++ tools/tools/netrate/http/http.c	(working copy)
@@ -308,7 +308,7 @@
 		statep->hwd[i].hwd_count = 0;
 		if (threaded) {
 			if (pthread_create(&statep->hwd[i].hwd_thread, NULL,
-			    http_worker, &statep->hwd[i]) < 0)
+			    http_worker, &statep->hwd[i]) != 0)
 				err(-1, "pthread_create");
 		} else {
 			curthread = i;
Index: tools/tools/netrate/httpd/httpd.c
===================================================================
--- tools/tools/netrate/httpd/httpd.c	(revision 203781)
+++ tools/tools/netrate/httpd/httpd.c	(working copy)
@@ -280,7 +280,7 @@
 	for (i = 0; i < THREADS; i++) {
 		if (threaded) {
 			if (pthread_create(&statep->hts[i].hts_thread, NULL,
-			    httpd_worker, &statep->hts[i]) < 0)
+			    httpd_worker, &statep->hts[i]) != 0)
 				err(-1, "pthread_create");
 		} else {
 			pid = fork();
Index: tools/tools/netrate/juggle/juggle.c
===================================================================
--- tools/tools/netrate/juggle/juggle.c	(revision 203781)
+++ tools/tools/netrate/juggle/juggle.c	(working copy)
@@ -337,7 +337,7 @@
 	if (pthread_mutex_init(&threaded_mtx, NULL) < 0)
 		err(-1, "thread_juggle: pthread_mutex_init");
 
-	if (pthread_create(&thread, NULL, juggling_thread, &fd2) < 0)
+	if (pthread_create(&thread, NULL, juggling_thread, &fd2) != 0)
 		err(-1, "thread_juggle: pthread_create");
 
 	if (pthread_mutex_lock(&threaded_mtx) < 0)


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list