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);
  }
}

Recommended Answers

Those are warnings and that is because you have no included <stdio.h>.

Jump to Post

All 2 Replies

Those are warnings and that is because you have no included <stdio.h>.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.