-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
adding thread_group for managing async tasks #1291
adding thread_group for managing async tasks #1291
Conversation
I'm afraid I can't review that, I don't know enough about C++. |
lol @moneromooo-monero:) This looks like a job for... @hyc ! |
I've done 1 quick pass thru this commit and the previous PR. My general impression is this looks like a good way to go. In general I would prefer that we have 1 persistent thread pool instead of spawning and killing threads everywhere we use them. Will look in more detail later. |
@NanoAkron It sounds like this would alleviate that problem, but I would have to investigate it some more. A stop function could be added which would abort processing on each thread after it completed the current dispatched function, but I think a @hyc I agree completely. Allocating threads inside of a function is not ideal. Ideally there would be one group of threads handling background tasks and I/O. I've come up with a slightly different design that uses Edit: Some botched grammar in first portion. |
It seems to make sense. |
NanoAkron: the delay in stopping is when syncing, and isn't due to that, but to the block loop not breaking when a shutdown is requested (it doesn't have access to the class which holds that flag, though a pointer to the flag (or some callback checking it) could be passed in ctor IIRC). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed
64094e5 adding thread_group for managing async tasks (Lee Clagett)
[ 19%] Building CXX object src/common/CMakeFiles/obj_common.dir/thread_group.cpp.o |
Possibly meant this, but I wouldn't bet my life on it :) diff --git a/src/common/thread_group.cpp b/src/common/thread_group.cpp |
Correct, that is supposed to be |
Thanks for the sanity check. |
Sorry guys, I should have caught this sooner - this patch uses std::mutex and std::unique_lock, which are unusable on Windows. We have to use boost:: for everything. |
The attached lets it compile under windows. Works OK on Win32. |
And mingw continues to frustrate me ... I suppose compiling with a closed source program (MSVC) is undesirable? I have some tests sitting around that I should've pushed a while ago, looks like I will add this change to that request. What happens to the builds that fired for this? I thought they passed, but obviously they couldn't have. |
Fyi, this is the beginning of the compile errors I hit - there was quite a long stream of errors after these:
|
I just replaced |
??? kovri uses Did I miss something (within the conversation or on IRC)? |
This topic is definitely confusing. There is I looked through the source for |
Mingw provides support for these things, but at least in gcc 4.x it's buggy on win32. We deliberately do not use these in the Monero code base because of that. |
@vtnerd I documented all of this here https://forum.getmonero.org/5/support/2510/building-monero-v0-9-2-on-win32 |
@vtnerd JFTR, as you can tell by my carelessness for grammar and pronouns, and in an effort to save time typing (of which I've now doubled-down over by responding), I say mingw as a catch-all for mingw-w64 (I know the differences 😄). As for the wrapper, that's good to know. @hyc how applicable are the 5.3.0 optimization bugs referenced in that link (8 months later)? |
I really don't know. Have not moved any of my builds off gcc 4.9. |
This pull request switches everything to |
Looking for general feedback (tests need to be written, etc., before merging)...
This was from a discussion in a prior pull request. This does not use
asio::io_service
because it is a bit clunky to wait for all threads to completeio::service::run()
(to guarantee that all handlers have completed), then restart theio::service::run()
to re-use the threads - busy spin loops or condition variables would be needed which makes the implementation look similar to this. I added the thread re-use "feature" because one of the functions inrctSigs.cpp
created two differentthread_group
objects, mainly so that the dispatched functions were guaranteed to complete before moving to the next section. Arguably,std::future
should be used instead - retrieving values would be sequenced specifically with the associated tasks, which would require some additional allocations for the shared_state inside ofstd::future
(and thus be some amount slower). Or maybe thethread_group
should be a "one shot" like it is currently (i.e. cannot re-use threads after synchronization). So the obvious choices are: (1) no change, (2) this, (3) this style withasio::io_service
and thread joining after each group of tasks, or (4) this style withasio::io_service
andstd::future
for blocking after each group of tasks.This can be used by blockchain.cpp and wallet2.cpp which requires similar changes. Also:
join
ing the thread, allowing for thread-reuse (seerctSigs.cpp
)Disadvantages:
asio::io_service
would allow for running I/O events on the same threads (I didn't see any obvious place where a refactor would allow this).asio::io_service
would have less hand-rolled stuff