NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

link as -lc -lpthread hangs



Hi,
I am using NetBSD rtld implementation in my library.
I am facing some issue when the application is built by linking
with libc before libpthread. i.e  '-lc -lpthread' as shown below

/usr/local/${ARCH}-linux/gcc app.c -o app -lc -lpthread

When i run the 'app' it hangs.

$ ./app
main is waiting
^Z
[1]+  Stopped                 ./app

Is the same behavior seen with respect to NetBSD libraries.

The sample test code is as below:
$ cat  app.c
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

#define THREAD_NUM      1

#define EXE_NAME "/bin/ls"


void* thread0(void *arg)
{
  sleep(1);
  return(NULL);
}

int main()
{
  int ret = 0;
  pid_t pid;
  pthread_t tid;
  int status ;

     ret = pthread_create(&tid,NULL,thread0,NULL);
     if (ret != 0) {
       printf("Can not create thread ,ret=%d\n",ret);
       return -1;
     }

 /*
  * Create child which does 'execl'
  */
  pid = fork();
  if(pid == 0) {
        execl(EXE_NAME, EXE_NAME, NULL);
        exit(0);
        }
      ret = pthread_join(tid,NULL) ;
      if (ret!=0) {
         printf("Can not join thread ret=%d\n",ret);
         return -1;
      }
 /*
  * Main waits for the child and if
  * libc is linked before lpthread
  * -lc -lpthread the parent waits forever
  */
 printf("main is waiting\n");
 wait(&status);
 return 0;
}

This issue is noticed only when the link is '-lc -lpthread'.
Please help me in this regard.

Waiting for your reply

Thanks & Regards,
Channa


Home | Main Index | Thread Index | Old Index