1+ /*
2+ * Copyright (c) 2025, NVIDIA CORPORATION.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions andc
14+ * limitations under the License.
15+ */
16+
17+ #include < atomic>
18+ #include < functional>
19+ #include < future>
20+ #include < thread>
21+ #include < type_traits>
22+ #include < vector>
23+
24+ namespace kvikio {
25+ /* *
26+ * @brief A simple thread pool that executes tasks in an embarrassingly parallel manner.
27+ *
28+ * The implementation is header-only.
29+ */
30+ class ThreadPoolSimple {
31+ public:
32+ ThreadPoolSimple (
33+ unsigned int num_threads, const std::function<void ()>& worker_thread_init_func = [] {})
34+ : _num_threads{num_threads}, _worker_thread_init_func{worker_thread_init_func}
35+ {
36+ }
37+
38+ void reset ();
39+
40+ template <typename F, typename R = std::invoke_result_t <std::decay_t <F>>>
41+ [[nodiscard]] std::future<R> submit_task (F&& task)
42+ {
43+ }
44+
45+ private:
46+ void worker () {}
47+
48+ void create_threads ()
49+ {
50+ for (unsigned int i = 0 ; i < _num_threads; ++i) {
51+ _thread_container.emplace_back (&ThreadPoolSimple::worker, _worker_thread_init_func);
52+ }
53+ }
54+
55+ void destroy_threads () {}
56+
57+ std::atomic_bool _done{false };
58+ unsigned int _num_threads{};
59+ std::function<void ()> _worker_thread_init_func{};
60+ std::vector<std::thread> _thread_container{};
61+ };
62+
63+ } // namespace kvikio
0 commit comments