From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8525 Path: news.gmane.org!not-for-mail From: Julien Ramseier Newsgroups: gmane.linux.lib.musl.general Subject: pthread_join stuck in infinite loop Date: Sun, 20 Sep 2015 20:07:28 +0200 Message-ID: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2102\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_F3B89601-C913-4D6F-9849-BC2581B2480F" X-Trace: ger.gmane.org 1442772483 20962 80.91.229.3 (20 Sep 2015 18:08:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 20 Sep 2015 18:08:03 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8537-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 20 20:08:02 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Zdj1l-0002RF-O9 for gllmg-musl@m.gmane.org; Sun, 20 Sep 2015 20:07:53 +0200 Original-Received: (qmail 32113 invoked by uid 550); 20 Sep 2015 18:07:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 32034 invoked from network); 20 Sep 2015 18:07:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:subject:message-id:date:to:mime-version; bh=84UfdSXZD6lWnhRkFmBZsiUfPZVw2i0ec1T1F7o2dP8=; b=WpduVDDRX3uOD4OH+neXLAGImP1HtdaMp+rG71Q3RPSxGbUPlLuKXGgZv1i6YULPKH DmpbZMHfZ1nihI2HxgTJUsJuUxvplC5bbuUDdV5SQvN2lkQ2fXa8m002NYyUAIG5akGK dNn/jGP0OZjys3VJQvSxzdj+/PUHJLutxZEO47IA7/++e9Xcsprm0K3Bso0/w0nslSV0 Aka8v0m7mq1rCx7NLl4nUknoTEtCdCFn/aDAue8cj/P4S4O3F5m3HeSmN7fwOVYJ1+dT 6Xfu+VWgTlNHFIcqW6t3waj/taYedPvWf9U9xGuIql3KCVCmepDVqdvQCHg1nAS7DY+m giTw== X-Received: by 10.194.113.101 with SMTP id ix5mr20900553wjb.66.1442772450699; Sun, 20 Sep 2015 11:07:30 -0700 (PDT) X-Mailer: Apple Mail (2.2102) Xref: news.gmane.org gmane.linux.lib.musl.general:8525 Archived-At: --Apple-Mail=_F3B89601-C913-4D6F-9849-BC2581B2480F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hello, pthread_join() never returns when calling it on a detached thread. I would expect it to return EINVAL instead. Here=E2=80=99s a small test case: #include #include #include #include void *world_thd(void *arg) { sleep(2); return NULL; } int main() { int ret; pthread_t thd; pthread_attr_t attr; if (pthread_attr_init(&attr)) return 1; if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) return 1; if (pthread_create(&thd, &attr, world_thd, NULL))=20 return 1; ret =3D pthread_join(thd, NULL); if (ret =3D=3D EINVAL) printf("Thread is not joinable\n"); else { fprintf(stderr, "Failed to join thread: %i\n", ret); return 1; } return 0; } -- Julien --Apple-Mail=_F3B89601-C913-4D6F-9849-BC2581B2480F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hello,

pthread_join() never returns when calling it on a detached = thread.
I would expect it to return EINVAL = instead.

Here=E2=80=99s a small test case:

#include <pthread.h>
#include <stdio.h>
#include = <errno.h>
#include <unistd.h>

void *world_thd(void *arg) = {
= sleep(2);
= return NULL;
}

int main() {
int ret;
pthread_t = thd;
= pthread_attr_t attr;

if = (pthread_attr_init(&attr))
return = 1;
if = (pthread_attr_setdetachstate(&attr, = PTHREAD_CREATE_DETACHED))
return = 1;
if = (pthread_create(&thd, &attr, world_thd, = NULL)) 
= return 1;

ret =3D pthread_join(thd, = NULL);
if (ret = =3D=3D EINVAL)
= printf("Thread is not joinable\n");
else = {
= fprintf(stderr, "Failed to join thread: %i\n", = ret);
= return 1;
= }
= return 0;
}


--
Julien

= --Apple-Mail=_F3B89601-C913-4D6F-9849-BC2581B2480F--