Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug in structured-concurrency tutorial #213

Open
suvarchal opened this issue Jan 3, 2022 · 1 comment
Open

A bug in structured-concurrency tutorial #213

suvarchal opened this issue Jan 3, 2022 · 1 comment

Comments

@suvarchal
Copy link

In section
What are the use cases? > Parent coroutine closes child coroutine
http://libdill.org/structured-concurrency.html#parent-coroutine-closes-child-coroutine

In the code example shown,i think, does not fit to the description, it was a bit of confusion for me until to realize later it might be a bug in the example.
Given example

coroutine void worker(void) {
    int rc = msleep(now() + 2000);
    if(rc < 0 && errno == ECANCELED) return; /* 4. */
    /* 2. */
}

int main(void) {
    int cr = go(worker()); /* 1. */
    msleep(now() + (random() % 1000));
    hclose(cr); /* 3. */
    return 0;
}

should be with random deadline in the worker

coroutine void worker(void) {
    int rc = msleep(now() + (random() % 1000));
    if(rc < 0 && errno == ECANCELED) return; /* 4. */
    /* 2. */
}

int main(void) {
    int cr = go(worker()); /* 1. */
    msleep(now() + 2000);
    hclose(cr); /* 3. */
    return 0;
}

btw thanks for the wonderful library and well thought examples in tutorial.

@plazer1
Copy link

plazer1 commented Mar 9, 2022

I noticed this as well. Funnily enough, your correction is incorrect too. It should be like this:

coroutine void worker(void) {
    int rc = msleep(now() + (random() % 2000));
    if(rc < 0 && errno == ECANCELED) return; /* 4. */
    /* 2. */
}

int main(void) {
    int cr = go(worker()); /* 1. */
    msleep(now() + 1000);
    hclose(cr); /* 3. */
    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants