0% found this document useful (0 votes)
14 views

exp6

The document contains a program written in C that demonstrates concurrent execution of threads using the pthreads library. It defines two threads, 'mythread1' and 'mythread2', which print numbers from 1 to 10. The main function creates these threads and waits for their completion before exiting.

Uploaded by

23b01a1253
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

exp6

The document contains a program written in C that demonstrates concurrent execution of threads using the pthreads library. It defines two threads, 'mythread1' and 'mythread2', which print numbers from 1 to 10. The main function creates these threads and waits for their completion before exiting.

Uploaded by

23b01a1253
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

REGD NO : 23B01A12I3

NAME : V.PRAVALIKA

EXPERIMENT 6

Write a program to illustrate concurrent execution of threads using pthreads library

PROGRAM :
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
void *mythread1(void *vargp)
{
int i;
printf("thread1\n");
for(i=1;i<=10;i++)
printf("i=%d\n",i);
printf("exit from thread1\n");
return NULL;
}
void *mythread2(void *vargp)
{
int j;
printf("thread2 \n");
for(j=1;j<=10;j++)

printf("j=%d\n",j);
printf("Exit from thread2\n");
return NULL;
}
int main()
{
pthread_t tid;
printf("before thread\n");
pthread_create(&tid,NULL,mythread1,NULL);
pthread_create(&tid,NULL,mythread2,NULL);
pthread_join(tid,NULL);
pthread_join(tid,NULL);
exit(0);
}

OUTPUT :

You might also like