#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
struct process
{
char name;
double BT;
}p[5];
int turn=0;
void startnext(int tid)
{
if(tid==1)
return;
tid++;
}
void run(void *tid)
{
int i=(int )tid;
while(turn!=i)
{
sleep(p[i].BT);
p[i].BT=0;
startnext(i);
pthread_exit(0);
}
}
int main(int argc,char *argv[])
{
pthread_t thrs[5];
int i,j;
if(argc==6)
{
for(i=0;i<5;i++)
{
p[i].name=65+i;
p[i].BT=atoi(argv[i+1]);
}
}
for (int i = 0; i < 5; i++)
{
pthread_create(&thrs[i],NULL,&run,(void *)i);
pthread_join(thrs[i],NULL);
}
return 0;
}
Friday, September 4, 2015
first come first serve Operating system c code
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment