[FUGSPBR] Fw: GCC + thread

Giovanni P. Tirloni gpt em tirloni.org
Qua Abr 30 10:33:19 BRT 2003


* Fernando (fern2 em wings.com.br) wrote:
> bom Dia ...
> 
>  Instalei o FreeBSD 4.7 standart e estou tentando compilar em C um exemplo
> de
>  Thread.
>  Mas ocorre o seguinte erro ..
> 
>  1. tentativa
>  turbo# gcc -o arq -lpthread pri.c
>  /usr/libexec/elf/ld: cannot find -lpthread
> 
>  2. tentativa
>  turbo# gcc -o arq -pthread pri.c
>  /tmp/ccCLXG8d.o: In function `thread_function':
>  /tmp/ccCLXG8d.o(.text+0x45): undefined reference to `a_thread_exit'
> 
>  O que esta errado ... tenho que instalar mais alguma coisa ???
>  Estou trabalhando com socket e tudo ok ... o problema eh quando tento
>  compilar alguma coisa com Thread.
> 
>  Obrigado
>  Fernando
> 
> 
>  <pri.c>
>  #include <stdio.h>
>  #include <unistd.h>
>  #include <stdlib.h>
>  #include <pthread.h>
> 
>  char message[] = "Hello World";
> 
>  void *thread_function(void *arg) {
>    printf("thread_function is running. Argument was %s\n", (char *)arg);
>    sleep(3);
>    strcpy(message, "Bye!");
>    a_thread_exit("Thank you for the CPU time");


 pthread_exit("Thank you for you the CPU time");


>  }
> 
> 
>  int main() {
>    int res;
>    pthread_t a_thread;
>    void *thread_result;
>    res = pthread_create(&a_thread, NULL,
>    thread_function, (void *)message);
>    if (res != 0) {
>      perror("Thread creation failed");
>      exit(EXIT_FAILURE);
>    }
>    printf("Waiting for thread to finish...\n");
>    res = pthread_join(a_thread,&thread_result);
>    if (res != 0) {
>      perror("Thread join failed");
>      exit(EXIT_FAILURE);
>    }
>    printf("Thread joined, it returned %s\n", (char *)thread_result);
>    printf("Message is now %s\n", message);
>    exit(EXIT_SUCCESS);
>  }
> 
> 
> 
> 
> 
> _______________________________________________________________
> Sair da Lista: http://www2.fugspbr.org/mailman/listinfo/fugspbr
> Historico: http://www4.fugspbr.org/lista/html/FUG-BR/

 --
 Giovanni P. Tirloni
 http://www.tirloni.org
_______________________________________________________________
Sair da Lista: http://www2.fugspbr.org/mailman/listinfo/fugspbr
Historico: http://www4.fugspbr.org/lista/html/FUG-BR/



Mais detalhes sobre a lista de discussão freebsd