szaszm commented on a change in pull request #1044:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1044#discussion_r636208293



##########
File path: extensions/systemd/WorkerThread.h
##########
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "utils/MinifiConcurrentQueue.h"
+
+#include <future>
+#include <thread>
+
+namespace org { namespace apache { namespace nifi { namespace minifi { 
namespace extensions { namespace systemd {
+
+namespace detail {
+class WorkerThread final {
+ public:
+  WorkerThread();
+
+  WorkerThread(const WorkerThread&) = delete;
+  WorkerThread(WorkerThread&&) = delete;
+  WorkerThread& operator=(WorkerThread) = delete;
+
+  ~WorkerThread();
+
+  template<typename... Args>
+  void enqueue(Args&&... args) { 
task_queue_.enqueue(std::forward<Args>(args)...); }
+
+ private:
+  void run() noexcept;
+
+  utils::ConditionConcurrentQueue<std::packaged_task<void()>> task_queue_;
+  std::thread thread_;
+};
+}  // namespace detail
+
+/**
+ * A worker that executes arbitrary functions with no parameters 
asynchronously on an internal thread, returning a future to the result.
+ */
+class Worker final {

Review comment:
       Here's a list of the data members of ThreadPool:
   ```
   // determines if threads are detached
     bool daemon_threads_;
     std::atomic<int> thread_reduction_count_;
   // max worker threads
     int max_worker_threads_;
   // current worker tasks.
     std::atomic<int> current_workers_;
     std::atomic<int> task_count_;
   // thread queue
     std::vector<std::shared_ptr<WorkerThread>> thread_queue_;
   // manager thread
     std::thread manager_thread_;
   // the thread responsible for putting delayed tasks to the worker queue when 
they had to be put
     std::thread delayed_scheduler_thread_;
   // conditional that's used to adjust the threads
     std::atomic<bool> adjust_threads_;
   // atomic running boolean
     std::atomic<bool> running_;
   // controller service provider
     std::shared_ptr<core::controller::ControllerServiceProvider> 
controller_service_provider_;
   // integrated power manager
     std::shared_ptr<controllers::ThreadManagementService> thread_manager_;
     // thread queue for the recently deceased threads.
     ConcurrentQueue<std::shared_ptr<WorkerThread>> deceased_thread_queue_;
   // worker queue of worker objects
     ConditionConcurrentQueue<Worker<T>> worker_queue_;
     std::priority_queue<Worker<T>, std::vector<Worker<T>>, 
DelayedTaskComparator<T>> delayed_worker_queue_;
   // mutex to  protect task status and delayed queue
     std::mutex worker_queue_mutex_;
   // notification for new delayed tasks that's before the current ones
     std::condition_variable delayed_task_available_;
   // map to identify if a task should be
     std::map<TaskId, bool> task_status_;
   // manager mutex
     std::recursive_mutex manager_mutex_;
     // thread pool name
     std::string name_;
   ```
   
   and this is the same for `systemd::detail::WorkerThread`:
   ```
     utils::ConditionConcurrentQueue<std::packaged_task<void()>> task_queue_;
     std::thread thread_;
   ```
   
   I think this shows that these things are not the same. `systemd::Worker` is 
just a thread that executes functions in order. `utils::ThreadPool` is a 
scheduler with priority support, a thread pool, it can be stopped, resumed, and 
a lot more. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to