-
Notifications
You must be signed in to change notification settings - Fork 128
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
[HOLD MERGE PLEASE] ThreadPool compile time template parameter; CMake + CI cross platform work #9
Conversation
…atform specific fallbacks
… add TASK_SIZE template parameter to Worker for flexibility
* add package config installation * use cmake submodules for `thread_local` platform checks * add options for building tests and benchmarks (default off for lib builds) Note: Version 1.0.0 is used in previous hunter-packages release; imcrementing to 1.1.0 based on API mods Use INTERFACE library build
error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
* include(CTest) (optional) * replace add_custom_command() with add_test() Replace relative path syntax for COMMAND with cmake executable name to support default installation paths
error: 'test.hpp' file not found with <angled> include; use "quotes" instead
include_directories("${THREAD_POOL_CPP_INC_DIR}"): provided in top cmake
provide better default cmake policy settings (visibility, etc)
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.
Minor nitpicks
@@ -88,50 +82,25 @@ struct RepostJob | |||
// Heavy heavy; | |||
|
|||
ThreadPoolStd* thread_pool; | |||
#ifndef WITHOUT_ASIO | |||
AsioThreadPool* asio_thread_pool; | |||
#endif | |||
|
|||
volatile size_t counter; |
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.
All occurrences of size_t
should be properly qualified as std::size_t
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.
Agreed. I can replace size_t -> std::size_t in this PR.
#include "./worker.hpp" | ||
|
||
#define _tp_unused(x) ((void)(x)) |
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.
I'm not a fan of this macro. I think that (void) something;
is idiomatic C++ and doesn't require a macro.
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.
Done.
} | ||
|
||
template <typename TSettings> | ||
inline Worker& ThreadPool<TSettings>::getWorker() | ||
inline typename ThreadPool<TSettings>::FixedWorker& ThreadPool<TSettings>::getWorker() |
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.
inline auto&
would be nicer IMHO.
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.
Done.
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.
I realized this is a pure C++14 feature, so I will revert this and move the inline method inside the of the class to avoid the syntax issue:
FixedWorker & getWorker()
{
auto id = FixedWorker::getWorkerIdForCurrentThread();
if(id > m_workers.size())
{
id = m_next_worker.fetch_add(1, std::memory_order_relaxed) % m_workers.size();
}
return *m_workers[id];
}
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.
Aren't we targeting C++14 though? If you feel like this should target C++11 (to reach more people) we should discuss about that and eventually change the README. I like targeting the newest standard because it drives people to update their toolchains and to learn the new features/idioms. Thoughts, @inkooboo?
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.
I can understand that. If you both feel these changes aren't compatible with the project objectives, I can maintain a c++1y
fork as needed.
LGTM apart from some minor nitpicks. I'm not sure about the value of |
Thanks for the review. This ATTRIBUTE_TLS is necessary for my builds, and the mods support a fairly wide range of compilers (various flavors of iOS, Android, OS X, MSVC). If these backwards compatibility changes can be merged, and don't get in the way, that would be quite useful. For the current thread-pool-cpp functionality, this seems reasonable, and may support a larger initial audience. If this gets in the way at some point, and some core functionality requiring C++14 is added that can't be made optional (I can imagine such cases), then I can work in a fork until I can upgrade. The README does clearly state this is a C++14 thread pool, so I have no good argument for the C++11-ish support, other than the fact that I need it 😄, and I think this is still a practical limitation for a fairly wide range of applications (even in 2017). @inkooboo , @SuperV1234 : Let me know if you are both okay with this for now. |
Another small change...
I think this should be maintainable:
|
* add option for c++14 support (w/ c++1y fallback) top top level CMakeLists.txt * add initial appveyor.yml and .travis.yml * add per toolchain HAS_CPP14 variable in CI files * formatting * support MSVC flags in top level CMakeLists.txt * avoid running tests for IOS and ANDROID platforms * use ATTRIBUTE_TLS definition * detect and link threads (as needed) portably ``` terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not permitted ```
@inkooboo , @SuperV1234 : The above commit adds initial Travis and ASppveyor CI testing, and fixes a few issues I uncovered during testing. These are modified from the current CI tests in Hunter. We can add additional toolchains as needed, but this would at least provide some stability for new PR's. I ran this locally in my fork and all toolchains are currently passing. @inkooboo : I believe you will need to enable hooks for these in your account. For now we can commit them at least. I'm going to remove the "DO NOT MERGE" tag. Here is a summary: Here are the Linux + OS X platform host builds (TARGET: iOS, Android, MSVC, OS X and Linux)
Here are the Appveyor MSCV builds:
https://travis-ci.org/headupinclouds/thread-pool-cpp/builds/189887074 |
|
||
option(THREAD_POOL_CPP_HAS_CPP14 "Has true C++14 support." ON) | ||
|
||
if(NOT MSVC) |
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.
Could this work to avoid the explicit branching? https://cmake.org/cmake/help/v3.1/prop_tgt/CXX_STANDARD.html
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.
I'm not sure. I will take a look.
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.
Could this work to avoid the explicit branching
It looks like this isn't supported for interface libraries: http://stackoverflow.com/q/29687331
"Indeed, it is a deliberate design choice not to support a INTERFACE_CXX_STANDARD target property. See also the CMAKE_CXX_STANDARD variable. "
But the target_compile_features() are.... That may not necessarily help too much.
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.
I think something like this might work (and is a little cleaner):
if(THREAD_POOL_HAS_CPP14)
set(CMAKE_CXX_STANDARD 14)
else()
set(CMAKE_CXX_STANDARD 11)
endif()
target_compile_features(
thread-pool-cpp
INTERFACE
cxx_auto_type
cxx_nullptr
cxx_lambdas
cxx_lambda_init_captures
)
I'm testing these in my current projects and am thinking about the compiler flags, in addition to the I realized we should use Also, since this is a header only library, and we are using |
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.
I'm going to merge it offline, leaving all code improvements and part of build system improvements.
Also CI integration to be added but with lighter setup.
Ok. This one is long overdue (from indecision as much as anything else). Sorry about that. In my last testing I recall messing with:
had the some unintended consequences (which may vary based on the CMake version). For example, this ended up setting Here is the latest one I've been using (w/ C++11 compatibility): https://github.com/hunter-packages/thread-pool-cpp/commits/hunter This is some logic I had added to test for https://github.com/hunter-packages/thread-pool-cpp/blob/hunter/CMakeLists.txt#L20-L28 Let me know if there is something I can help with. I will have some time this weekend. |
The full compiler logic is provided here (I've been testing this with a fairly broad range of toolchains in CI without issue):
Thanks again for a great lib! |
@inkooboo , @SuperV1234 : Please see below and share any comments. Once this looks good, I can run some cross platform tests, we can merge, and I will look at adding basic CI tests (this can be run by hunter for each release by default if the package is accompanied with an example build test).
TSettings
template parameter toThreadPool
to specify task_size at compile time, and for forward API stability, updated internal code...tp
namespace, add optionalboost::future
support #5project(thread-pool-cpp VERSION 1.1.0)
: 1.0.0 used in previous hunter releasethread_local
and various fallbacks (FATAL_ERROR if no found)cmake_minimum_required(VERSION 3.3)
for more modern cmake policy defaultsfind_package
use (see example below)process()
api back forpackaged_task
interfaceThe current installation path and package config files look like this:
With this configuration, the project can be installed and included using:
It will also support automatic package management through hunter if used in a project w/ a top level
HunterGate()
command with one additional line. The previousinclude
path addition allows both direct/submodule use and post install (package) use with similar#include
syntax: