Skip to content

Commit d551202

Browse files
committed
v1.0.0
1 parent 6e51197 commit d551202

4 files changed

Lines changed: 35 additions & 24 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
44

55
project(
66
RiftenThiefpool
7-
VERSION 0.2.0
7+
VERSION 1.0.0
88
LANGUAGES CXX
99
)
1010

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
11
# `riften::Thiefpool`
22

3-
A Light, fast, work-stealing thread-pool for C++20. Built on the [`riften::Thiefpool`](https://github.com/ConorWilliams/ConcurrentDeque).
3+
A blazing-fast, lightweight, work-stealing thread-pool for C++20. Built on the lock-free concurrent [`riften::Deque`](https://github.com/ConorWilliams/ConcurrentDeque).
44

55
## Usage
66

77
```C++
8-
98
#include "riften/thiefpool.hpp"
109

1110
// Create thread pool with 4 worker threads.
1211
riften::Thiefpool pool(4);
1312

14-
// Enqueue and store future.
13+
// Enqueue and return future.
1514
auto result = pool.enqueue([](int x) { return x; }, 42);
1615

1716
// Get result from future.
1817
std::cout << result.get() << std::endl;
18+
```
19+
20+
Additionally, `riften::Thiefpool` supplies a detaching version of enqueue:
1921
22+
```C++
23+
// Enqueue and return nothing
24+
pool.enqueue_detach([](int x) { do_work(x); }, x);
2025
```
26+
Which elides the allocation of a `std::future`'s shared state.
2127

2228
## Installation
29+
30+
The recommended way to consume this library is through [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake), just add:
31+
32+
```CMake
33+
CPMAddPackage("gh:ConorWilliams/Threadpool#v1.0.0")
34+
```
35+
to your `CMakeLists.txt` and you're good to go!
36+
37+
## Tests
38+
39+
To compile and run the tests:
40+
```zsh
41+
mkdir build && cd build
42+
cmake ../test
43+
make && make test
44+
```

include/riften/thiefpool.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace riften {
1919

2020
namespace detail {
2121

22-
// Bind F and args... into nullary lambda
22+
// Bind F and args... into a nullary lambda
2323
template <typename... Args, std::invocable<Args...> F> auto bind(F &&f, Args &&...arg) {
2424
return [f = std::forward<F>(f), ... arg = std::forward<Args>(arg)]() mutable -> decltype(auto) {
2525
return std::invoke(std::forward<F>(f), std::forward<Args>(arg)...);
@@ -53,8 +53,8 @@ template <typename F> NullaryOneShot(F &&) -> NullaryOneShot<F>;
5353

5454
} // namespace detail
5555

56-
// Lightweight, fast, work-stealing thread-pool for C++20. Built on the `riften::Thiefpool` concurrent
57-
// deque.
56+
// Lightweight, fast, work-stealing thread-pool for C++20. Built on the lock-free concurrent `riften::Deque`.
57+
// Upon destruction the threadpool blocks until all tasks have been completed and all threads have joined.
5858
class Thiefpool {
5959
public:
6060
// Construct a `Thiefpool` with `num_threads` threads.
@@ -89,7 +89,8 @@ class Thiefpool {
8989
}
9090

9191
// Enqueue callable `f` into the threadpool. It will be called by perfectly forwarding `args...` (unlike
92-
// std::async/std::bind/std::thread). Returns a `std::future<...>` which does not block upon destruction.
92+
// `std::async`/`std::bind`/`std::thread`). Returns a `std::future<...>` which does not block upon
93+
// destruction.
9394
template <typename... Args, std::invocable<Args...> F> auto enqueue(F &&f, Args &&...args) {
9495
//
9596
auto task = detail::NullaryOneShot(detail::bind(std::forward<F>(f), std::forward<Args>(args)...));
@@ -105,8 +106,8 @@ class Thiefpool {
105106
}
106107

107108
// Enqueue callable `f` into the threadpool. It will be called by perfectly forwarded `args...` (unlike
108-
// std::async/std::bind/std::thread). This version does *not* return a handle to the called function and
109-
// thus only accepts functions which return void.
109+
// `std::async`/`std::bind`/`std::thread`). This version does *not* return a handle to the called function
110+
// and thus only accepts functions which return void.
110111
template <typename... Args, std::invocable<Args...> F> void enqueue_detach(F &&f, Args &&...args) {
111112
// Cleaner error message than concept
112113
static_assert(std::is_same_v<void, std::invoke_result_t<F, Args...>>, "Function must return void.");
@@ -139,4 +140,4 @@ class Thiefpool {
139140
std::vector<std::jthread> _threads;
140141
};
141142

142-
} // namespace riften
143+
} // namespace riften

test/CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
22

33
# ---- Project ----
44

5-
project(RiftenThiefpoolTest
6-
LANGUAGES CXX
7-
)
5+
project(RiftenThiefpoolTest)
86

97
# ---- Options ----
108

@@ -42,16 +40,6 @@ add_executable(${PROJECT_NAME} "${sources}")
4240
# Link dependencies
4341
target_link_libraries(${PROJECT_NAME} PUBLIC doctest::doctest RiftenThiefpool::RiftenThiefpool ${CMAKE_THREAD_LIBS_INIT})
4442

45-
# enable compiler warnings
46-
if(NOT TEST_INSTALLED_VERSION)
47-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
48-
target_compile_options(RiftenThiefpool INTERFACE -Wall -Wpedantic -Wextra -Werror)
49-
elseif(MSVC)
50-
target_compile_options(RiftenThiefpool INTERFACE /W4 /WX)
51-
target_compile_definitions(${PROJECT_NAME} PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS)
52-
endif()
53-
endif()
54-
5543
enable_testing()
5644

5745
include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)

0 commit comments

Comments
 (0)