on for dining philosphers
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<semaphore.h>
void * func(int n);
int main()
{
pthread_t philosopher[5];
pthread_mutex_t chopstick[5];
int i,k;
void *msg;
for(i=1;i<=5;i++)
{
if(k==-1)
{
k=pthread_mutex_init(&chopstick[i],NULL);
printf("\n Mutex initialization failed”);
exit(1);
}
}
for(i=1;i<=5;i++)
kapthread_create(&philosopherſi],NULL,(void *)func.(int * )i);
if(k!=0)
{
printf("\n Thread creation error \n");
exit(1);
}
}
for(i=1;i<=5;i++)
k=pthread_join(philosopher[i],&msg);
if(k!=0)
{
printf("\n Thread join failed \n”);
exit(1);
Answers
Answered by
4
Answer:
nega tamil a unga intro solunga
Similar questions
Accountancy,
9 days ago
Biology,
19 days ago
Social Sciences,
19 days ago
History,
9 months ago
Math,
9 months ago
Chemistry,
9 months ago