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

usleep() is obsolete and context objects #607

Open
ghenry opened this issue Apr 20, 2022 · 2 comments
Open

usleep() is obsolete and context objects #607

ghenry opened this issue Apr 20, 2022 · 2 comments

Comments

@ghenry
Copy link
Collaborator

ghenry commented Apr 20, 2022

HI @aberaud

Just bringing in the new changes in your example into my code and note:

usleep(10000);

https://man7.org/linux/man-pages/man3/usleep.3.html#CONFORMING_TO

4.3BSD, POSIX.1-2001. POSIX.1-2001 declares this function
obsolete; use nanosleep(2) instead. POSIX.1-2008 removes the
specification of usleep().

so this fails to compile in my code.

Also, what's the benefit of bringing atomic_XXX? We also now have two set of ctx objects to manage.

Thanks.

@aberaud
Copy link
Member

aberaud commented Apr 27, 2022

The atomic boolean is simply used to pool-block for the shutdown callback (which is called from another thread).

The "optimal" way (with no pooling) would be to use a condition variable, but that was a bit overkill for that simple case.

If the bool was not atomic, it would be a data race, and it would in theory be possible (and valid, but unlikely in practice) for the main thread to keep using the CPU-core-cached value 'false' instead of the value 'true' stored by the shutdown callback.

Having many context objects is not a problem: these objects track the state of async operations like listen, get, or shutdown.
There should be one instance per operation performed, unless the user is not interested to know how the async op is doing.

@ghenry
Copy link
Collaborator Author

ghenry commented Apr 28, 2022 via email

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