mailing list of musl libc
 help / color / mirror / code / Atom feed
* segmentation fault on pthread_detach
@ 2018-03-27 12:00 Salman.Ahmed
  2018-03-27 12:32 ` Jens Gustedt
  0 siblings, 1 reply; 4+ messages in thread
From: Salman.Ahmed @ 2018-03-27 12:00 UTC (permalink / raw)
  To: musl

[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-27 13:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-27 12:00 segmentation fault on pthread_detach Salman.Ahmed
2018-03-27 12:32 ` Jens Gustedt
2018-03-27 12:51   ` AW: " Salman.Ahmed
2018-03-27 13:00     ` Szabolcs Nagy

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).