summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/dining_philosophers.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-06-11 14:03:16 +0200
committerTyge Løvset <[email protected]>2023-06-11 14:59:06 +0200
commitb564ef6bdfcd2437f1b4997f42054c45ccdedbb1 (patch)
treeb6c5458b8bc47279d18408f25e79eb6118808d78 /misc/examples/dining_philosophers.c
parentf3529a2600141dc7f84c734ea3bf5db8f7090e56 (diff)
downloadSTC-modified-b564ef6bdfcd2437f1b4997f42054c45ccdedbb1.tar.gz
STC-modified-b564ef6bdfcd2437f1b4997f42054c45ccdedbb1.zip
Added priv/linkage.h and renamed priv/template2.h => priv/template_undef.h.
Make all examples c++ compatible, except those using cspan.h Removed: crange_obj() Renamed: crange_make() => crange_init() Renamed: cspan_make() => cspan_init() Renamed: cstr_NULL => cstr_null Renamed: csview_NULL => csview_null
Diffstat (limited to 'misc/examples/dining_philosophers.c')
-rw-r--r--misc/examples/dining_philosophers.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/misc/examples/dining_philosophers.c b/misc/examples/dining_philosophers.c
index f9c05e71..e13eb055 100644
--- a/misc/examples/dining_philosophers.c
+++ b/misc/examples/dining_philosophers.c
@@ -29,9 +29,10 @@ struct Dining {
// Philosopher coroutine
void philosopher(struct Philosopher* p)
{
+ double duration;
cco_routine(p) {
while (1) {
- double duration = 1.0 + crandf()*2.0;
+ duration = 1.0 + crandf()*2.0;
printf("Philosopher %d is thinking for %.0f minutes...\n", p->id, duration*10);
cco_timer_await(&p->tm, duration);
@@ -46,7 +47,7 @@ void philosopher(struct Philosopher* p)
cco_sem_release(p->left_fork);
cco_sem_release(p->right_fork);
}
-
+
cco_final:
printf("Philosopher %d finished\n", p->id);
}