[ Foro de C ]

gcc thread.c -o thread -lpthread

27-Oct-2020 16:43
Invitado (Ivan rodellas garcia)
0 Respuestas

https://www.includehelp.com/c-programming-questions/compiling-program-with-pthread-library-linux.aspx

gcc thread.c -o thread -lpthread


#include <stdio.h>
#include <pthread.h>
 
/*thread function definition*/
void* threadFunction(void* args)
{
   while(1)
   {
       printf("I am threadFunction.\n");
   }
}
int main()
{
   /*creating thread id*/
   pthread_t id;
   int ret;
 
   /*creating thread*/
   ret=pthread_create(&id,NULL,&threadFunction,NULL);
   if(ret==0){
       printf("Thread created successfully.\n");
   }
   else{
       printf("Thread not created.\n");
       return 0; /*return from main*/
   }
 
   while(1)
   {
     printf("I am main function.\n");      
   }
 
   return 0;
}

He encontrado esta web sobre threads




(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)