diff options
| author | Tyge Løvset <[email protected]> | 2023-06-07 10:35:38 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-06-07 19:56:11 +0200 |
| commit | 56469c2738effe6d44a3a0c44e821c0ff18ce28e (patch) | |
| tree | 3bfe712740a7f4bd6cbfcea115b581def9071828 /misc/examples/dining_philosophers.c | |
| parent | 7c57f4fb7edf33d030975a04160f183f71c48ecd (diff) | |
| download | STC-modified-56469c2738effe6d44a3a0c44e821c0ff18ce28e.tar.gz STC-modified-56469c2738effe6d44a3a0c44e821c0ff18ce28e.zip | |
cco: Minor internal cleanup + added cco_timer_elapsed().
Diffstat (limited to 'misc/examples/dining_philosophers.c')
| -rw-r--r-- | misc/examples/dining_philosophers.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/misc/examples/dining_philosophers.c b/misc/examples/dining_philosophers.c index 57fcef56..f9c05e71 100644 --- a/misc/examples/dining_philosophers.c +++ b/misc/examples/dining_philosophers.c @@ -22,7 +22,6 @@ struct Dining { // Define semaphores for the forks cco_sem forks[num_forks]; struct Philosopher ph[num_philosophers]; - int ph_idx; int cco_state; // required }; @@ -43,7 +42,7 @@ void philosopher(struct Philosopher* p) duration = 0.5 + crandf(); printf("Philosopher %d is eating for %.0f minutes...\n", p->id, duration*10); cco_timer_await(&p->tm, duration); - + cco_sem_release(p->left_fork); cco_sem_release(p->right_fork); } @@ -69,8 +68,8 @@ void dining(struct Dining* d) while (1) { // per-"frame" logic update of all philosophers states - for (d->ph_idx = 0; d->ph_idx < num_philosophers; ++d->ph_idx) { - philosopher(&d->ph[d->ph_idx]); + for (int i = 0; i < num_philosophers; ++i) { + philosopher(&d->ph[i]); } cco_yield(); // suspend, return control back to main } |
