From: <Salman.Ahmed@weidmueller.com>
To: <musl@lists.openwall.com>
Subject: segmentation fault on pthread_detach
Date: Tue, 27 Mar 2018 12:00:39 +0000 [thread overview]
Message-ID: <E9B8FCA610BB6249B7C397BE4A01AE19412212@SRVDE355.weidmueller.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2572 bytes --]
Hello,
My application using musl libc runs into a seg fault if I call pthread_detach after pthread_join on the same thread. From my understanding pthread_detach should return ESRCH if a previous join was called on a particular thread. That’s the correct behavior I see if I run my program with glibc. But on my LEDE based router I run into the seg fault issue.
The cross compiling toolchain I use is arm_cortex-a9+neon_gcc-5.4.0_musl-1.1.16_eabi. Simple example I used for testing is below.
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>
void *print_message_function( void *ptr );
int main()
{
pthread_t thread1, thread2;
const char *message1 = "Thread 1";
const char *message2 = "Thread 2";
int iret1, iret2;
int dret1, dret2;
iret1 = pthread_create( &thread1, NULL, &print_message_function, (void*) message1);
if(iret1)
{
fprintf(stderr,"Error - pthread_create() return code: %d\n",iret1);
exit(EXIT_FAILURE);
}
iret2 = pthread_create( &thread2, NULL, &print_message_function, (void*) message2);
if(iret2)
{
fprintf(stderr,"Error - pthread_create() return code: %d\n",iret2);
exit(EXIT_FAILURE);
}
printf("pthread_create() for thread 1 returns: %d\n",iret1);
printf("pthread_create() for thread 2 returns: %d\n",iret2);
pthread_join( thread1, NULL);
pthread_join( thread2, NULL);
dret1 = pthread_detach(thread1);
if (dret1 == EINVAL) {
printf("got EINVAL when detaching 1\n");
}
if (dret1 == ESRCH) {
printf("got ESRCH when detaching 1\n");
}
dret2 = pthread_detach(thread2);
if (dret2 == EINVAL) {
printf("got EINVAL when detaching 2\n");
}
if (dret2 == ESRCH) {
printf("got ESRCH when detaching 2\n");
}
return 0;
}
void *print_message_function( void *ptr )
{
char *message;
message = (char *) ptr;
printf("%s \n", message);
}
Output gotten
pthread_create() for thread 1 returns: 0
Thread 1
pthread_create() for thread 2 returns: 0
Thread 2
Segmentation fault (core dumped)
Regards
Salman
________________________________
Kommanditgesellschaft - Sitz: Detmold - Amtsgericht Lemgo HRA 2790 -
Komplementärin: Weidmüller Interface Führungsgesellschaft mbH -
Sitz: Detmold - Amtsgericht Lemgo HRB 3924;
Geschäftsführer: José Carlos Álvarez Tobar, Elke Eckstein, Jörg Timmermann;
USt-ID-Nr. DE124599660
[-- Attachment #2: Type: text/html, Size: 14289 bytes --]
next reply other threads:[~2018-03-27 12:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-27 12:00 Salman.Ahmed [this message]
2018-03-27 12:32 ` Jens Gustedt
2018-03-27 12:51 ` AW: " Salman.Ahmed
2018-03-27 13:00 ` Szabolcs Nagy
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=E9B8FCA610BB6249B7C397BE4A01AE19412212@SRVDE355.weidmueller.com \
--to=salman.ahmed@weidmueller.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).