mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Piotr Tworek <tworaz666@gmail.com>
To: musl@lists.openwall.com
Cc: Piotr Tworek <tworaz666@gmail.com>
Subject: [PATCH] Don't return new thread ID from pthread_create.
Date: Thu, 16 Aug 2018 01:09:33 +0200	[thread overview]
Message-ID: <20180815230933.9962-1-tworaz@tworaz.net> (raw)

From: Piotr Tworek <tworaz666@gmail.com>

According to documentation pthread_create is supposed to return 0 on
success or error code in case of failure. Unfortunately this is not
always the case in musl. In case the application has called
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED),
pthread_create will return new thread ID. To make matters worse such non
zero value does not mean thread creation failed. Its quite the oposite.
Thread was created succesfully and start routine passed to pthread_create
will actually get invoked.

To fix the problem simply drop the return statement from the last
if statement in musl's pthread_create. The value currently being returned
from there is a return code from __clone. Negative values indicating
failure have already been handled by previous if statement and positive
value indicates everything went correctly and pthread_create should return 0.
---
 src/thread/pthread_create.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index 2df2e9f9..792cb42e 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -306,7 +306,6 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
 
 	if (do_sched) {
 		__futexwait(&ssa.futex, -1, 1);
-		if (ret) return ret;
 	}
 
 	*res = new;
-- 
2.16.4



             reply	other threads:[~2018-08-15 23:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-15 23:09 Piotr Tworek [this message]
2018-08-15 23:29 ` Rich Felker
2018-08-16  6:34   ` tworaz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180815230933.9962-1-tworaz@tworaz.net \
    --to=tworaz666@gmail.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).