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

doc: improve example docs/code/progress/main.c #4386

Open
bnoordhuis opened this issue Apr 9, 2024 · 1 comment
Open

doc: improve example docs/code/progress/main.c #4386

bnoordhuis opened this issue Apr 9, 2024 · 1 comment

Comments

@bnoordhuis
Copy link
Member

From the example:

percentage = downloaded*100.0/size;
async.data = (void*) &percentage;
uv_async_send(&async);

Multiple problems:

  1. uv_async_send() is not a memory barrier
  2. percentage goes out of scope when the thread exits, which can happen before the async callback runs
  3. An optimizing compiler may opt to do the calculation in place, meaning other threads may see a partial result

There's a sleep(1) right after so (2) is not super likely but it's still a bad example.

@juanarbol
Copy link
Contributor

You want is an example of async use? Or a different one from this one

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

No branches or pull requests

2 participants