summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/dining_philosophers.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-06-07 10:35:38 +0200
committerTyge Løvset <[email protected]>2023-06-07 19:56:11 +0200
commit56469c2738effe6d44a3a0c44e821c0ff18ce28e (patch)
tree3bfe712740a7f4bd6cbfcea115b581def9071828 /misc/examples/dining_philosophers.c
parent7c57f4fb7edf33d030975a04160f183f71c48ecd (diff)
downloadSTC-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.c7
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
}