void* philosopher(void* i){ int p = (int) i; while(1){ think(p); take_forks(p); eat(p); put_forks(p); } return 0; }
void * philosopher(void *param) // philosopher numbers { int i=*((int *)param); while(1) // while true repeat forever { sleep(1); //sleep for 1-> think take_forks(i); //acquire two forks or block sleep(2); //sleep that mean eat put_forks(i); //put forks on table } }
void philosopher (void *data) { int i; i = (int) data; for (;;) { think (i); get_forks (i, &fork [i], &fork [(i+1) % N]); eat (i); put_forks (&fork [i], &fork [(i+1) % N]); } }
void philosopher(void){ int32_t i; i = HF_CurrentTaskId() - 1; while (1){ think(); take_forks(i); eat(); put_forks(i); } }
void philosopher(int *pi) // pi is philosopher number casted to a pointer { int i = (int) pi; printf("philosopher thread %d starting...\n", i); while (!done) { think(i); // philosopher is thinking... take_forks(i); // acquire two forks or block eat(i); // yum, yum --- spaghetti! put_forks(i); // put both forks back on table } }
void *philosopher(void *arg) { int i = (int)arg; while (flag) { // think(i); take_forks(i); eat(i); put_forks(i); } pthread_exit(EXIT_SUCCESS); }
void philosopher(int i) /* i: philosopher number, from 0 to N1 */ { printf("Philosopher %d is thinking\n", i+1); time=rand() % MAX_THINK + MIN_THINK; /* philosopher is thinking */ sleep(time); take_forks(i); /* acquire two forks or block */ printf("Philosopher %d is eating\n", i+1); time=rand() % MAX_EAT + MIN_EAT; sleep(time); printf("Philosopher %d is done eating and back to thinking\n", i+1); put_forks(i); }
unsigned int __stdcall philosopher(void* k) { int numb = *((int*)k); while (!wndReady)Sleep(1000); while (true) { think(numb); Sleep(1000 + rand() % 100); take_forks(numb); Sleep(1000 + rand() % 100); eat(numb); Sleep(1000 + rand() % 100); put_forks(numb); Sleep(1000 + rand() % 100); } }
void philosopher(void const *i) { int index = (int)i; timer[index].start(); while(true){ think(index); Thread::wait(rand()%1000+4000);// if (timer[index].read_ms()>5000) { timer[index].reset(); timer[index].start(); take_forks(index); printer(); Thread::wait(rand()%1000+1000); put_forks(index); printer(); } } }
void * philosopher(void *arument) { int index = *(int *)arument; int k, t; for (k = 0; k < K; k++) { think(index); t = abs(rand() % 1000); usleep(t);//thinking take_forks(index); eat(index); t = abs(rand() % 1000); usleep(t);//eating put_forks(index); } return NULL; }
void *philosopher(void *id) { /* We know that this is always going to be a int */ int myId = *(int *)id; int i; /* Cycle through eating and thinking */ for (i = 0; i < numCycles; i++) { take_forks(myId); eat(myId); put_forks(myId); think(myId); /* If we don't set the state to changing here they will be * thinking while waiting for forks even though theyre hungry */ state[myId] = CHANGING; } return NULL; }
/* 哲学家线程 */ void phd_thread_entry(void* parameter) { int i; i = (int)parameter; rt_kprintf("phd %i starts...\n", i); while(1) { /* thinking */ rt_thread_delay(RT_TICK_PER_SECOND); rt_kprintf("phd %d is %s\n", i, status_string[phd_state[i]]); /* take forks */ take_forks(i); /* eating */ rt_kprintf("phd %d is %s\n", i, status_string[phd_state[i]]); rt_thread_delay(RT_TICK_PER_SECOND*2); /* put forks */ put_forks(i); } }