summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/coroutines/dining_philosophers.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-08-01 16:47:38 +0200
committerTyge Løvset <[email protected]>2023-08-01 18:09:40 +0200
commit94391527ef50cbee073a4b427f6fe839c010ecb1 (patch)
treef4d48b7efd6a11d94d08c4ef2ee599601b949dbb /misc/examples/coroutines/dining_philosophers.c
parent6354a597892e84baa6c3a99b98f2c7acaf33a99d (diff)
downloadSTC-modified-94391527ef50cbee073a4b427f6fe839c010ecb1.tar.gz
STC-modified-94391527ef50cbee073a4b427f6fe839c010ecb1.zip
Last minute API change for coroutines before V4.3 release:
- Renamed cco_xxxx_await() => cco_await_xxxx() (call, task, sem, timer) - Renamed cco_xxxx_blocking() => cco_blocking_xxxx() (call, task) - Renamed cco_task_resume() => cco_resume_task() - Simplified cco_blocking_call()
Diffstat (limited to 'misc/examples/coroutines/dining_philosophers.c')
-rw-r--r--misc/examples/coroutines/dining_philosophers.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/misc/examples/coroutines/dining_philosophers.c b/misc/examples/coroutines/dining_philosophers.c
index abe09204..e917c303 100644
--- a/misc/examples/coroutines/dining_philosophers.c
+++ b/misc/examples/coroutines/dining_philosophers.c
@@ -34,15 +34,15 @@ int philosopher(struct Philosopher* p)
while (1) {
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);
+ cco_await_timer(&p->tm, duration);
printf("Philosopher %d is hungry...\n", p->id);
- cco_sem_await(p->left_fork);
- cco_sem_await(p->right_fork);
-
+ cco_await_sem(p->left_fork);
+ cco_await_sem(p->right_fork);
+
duration = 0.5 + crandf();
printf("Philosopher %d is eating for %.0f minutes...\n", p->id, duration*10);
- cco_timer_await(&p->tm, duration);
+ cco_await_timer(&p->tm, duration);
cco_sem_release(p->left_fork);
cco_sem_release(p->right_fork);
@@ -94,10 +94,10 @@ int main(void)
cco_timer tm = cco_timer_from(15.0); // seconds
csrand((uint64_t)time(NULL));
- while (!cco_done(&dine)) {
+ cco_blocking_call(dining(&dine))
+ {
if (cco_timer_expired(&tm))
cco_stop(&dine);
- dining(&dine); // resume
cco_sleep(0.001);
++n;
}