Write C program to create a thread using pthreads library and let it run its function

Ram Pothuraju
Creating a (Default) Thread

Use the function pthread_create() to add a new thread of control to the current process. It is prototyped by:

int pthread_create(pthread\_t *tid, const pthread\_attr\_t *tattr,
void*(*start_routine)(void *), void *arg);

When an attribute object is not specified, it is NULL, and the default thread is created with the following attributes:
•It is unbounded
•It is nondetached
•It has a a default stack and stack size
•It inhetits the parent's priority


void *mythread(void *vargp)
  printf("welcome to IM CSEIAN ·\n");
  return NULL;
int main()
  pthread_t tid;
  printf("before thread\n");

Out Put :: 

To Compile 

cc filename.c –l pthread

To Run

Welcome to IM CSEIAN ·

Post a Comment


Post a Comment (0)