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

All 2 Replies

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

Member Avatar for Mouche

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.