0

am having these errors:

/home/Desktop/L5Q1.c: In function ‘main’:
/home/Desktop/L5Q1.c:15:9: warning: incompatible implicit declaration of built-in function ‘printf’
/home/Desktop/L5Q1.c: In function ‘funct1’:
/home/Desktop/L5Q1.c:26:9: warning: incompatible implicit declaration of built-in function ‘printf’

#include <pthread.h>

void * funct1(void * arg);

main()
{ 
  pthread_t threadid;
  int i,j;
  int x=1;                                                                            

 pthread_create(&threadid,NULL,funct1,(void *)&x);
  for (j=0; j <10; j++)
  { 
	for (i=0; i<1000; i++);
        printf("Hi I'm the parent\n");
	sleep(2);
  }
}
void * funct1(void * arg)
{ 
  int i,j;
 
  for (j=0;j<10; j++)
  { 
	for (i=0; i<1000; i++);
        printf("Hi I'm the created thread\n");
	sleep(1);
  }
}

Edited by techyworld: n/a

3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by Mouche
0

As a side note, you might want to create an attribute to make your thread JOINABLE and then join the thread at the end of main(). That ensures that main() does not exit before the thread is done.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.