[ 
https://issues.apache.org/jira/browse/MINIFI-236?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15949062#comment-15949062
 ] 

ASF GitHub Bot commented on MINIFI-236:
---------------------------------------

Github user phrocker commented on a diff in the pull request:

    https://github.com/apache/nifi-minifi-cpp/pull/71#discussion_r108924995
  
    --- Diff: libminifi/include/utils/ThreadPool.h ---
    @@ -0,0 +1,287 @@
    +/**
    + * 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.
    + */
    +#ifndef LIBMINIFI_INCLUDE_THREAD_POOL_H
    +#define LIBMINIFI_INCLUDE_THREAD_POOL_H
    +
    +#include <iostream>
    +#include <atomic>
    +#include <mutex>
    +#include <vector>
    +#include <queue>
    +#include <future>
    +#include <thread>
    +namespace org {
    +namespace apache {
    +namespace nifi {
    +namespace minifi {
    +namespace utils {
    +
    +/**
    + * Worker task
    + * purpose: Provides a wrapper for the functor
    + * and returns a future based on the template argument.
    + */
    +template< typename T>
    +class Worker{
    +public:
    +  explicit Worker(std::function<T()> &task) : task(task)
    +  {
    +    promise = std::make_shared<std::promise<T>>();
    +  }
    +
    +  /**
    +   * Move constructor for worker tasks
    +   */
    +  Worker(Worker &&other) : task (std::move(other.task)),
    +                                           promise(other.promise)
    +  {
    +  }
    +
    +
    +  /**
    +   * Runs the task and takes the output from the funtor
    +   * setting the result into the promise
    +   */
    +  void run()
    +  {
    +    T result = task();
    +    promise->set_value(result);
    +  }
    +
    +   Worker<T>(const Worker<T>&) = delete;
    +    Worker<T>& operator = (const Worker<T>&) = delete;
    +
    +  Worker<T>& operator = (Worker<T>&&) ;
    +
    +  std::shared_ptr<std::promise<T>> getPromise();
    +
    +private:
    +   std::function<T()> task;
    +   std::shared_ptr<std::promise<T>> promise;
    +};
    +
    +template< typename T>
    --- End diff --
    
    comment to remind people that && will take ownership of Worker


> Ensure processors are all thread safe
> -------------------------------------
>
>                 Key: MINIFI-236
>                 URL: https://issues.apache.org/jira/browse/MINIFI-236
>             Project: Apache NiFi MiNiFi
>          Issue Type: Bug
>          Components: C++
>            Reporter: marco polo
>            Assignee: marco polo
>            Priority: Critical
>             Fix For: cpp-0.2.0
>
>
> Found that RemoteProcessingGroup was not thread safe. Had to move peer and 
> protocol to be thread local variables to successfully allow more concurrent 
> threads to run onTrigger.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to