JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Async.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2021 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
20 #include <future>
21 #include <vector>
22 
23 namespace jevois
24 {
25  //! Async execution using a thread pool
26  /*! Same function signature and usage as std::async(). Always launches the task in a parallel thread, using a thread
27  pool. Runs the task on big (ARM A73) cores when using big.little CPU architecture of JeVois Pro Platform. Use this
28  function to launch parallel threads of high priority, e.g., machine vision algorithms. \ingroup utils */
29  template <class Function, class... Args>
30  [[nodiscard]] std::future<std::invoke_result_t<std::decay_t<Function>, std::decay_t<Args>...>>
31  async(Function && f, Args &&... args);
32 
33  //! Async execution using a thread pool
34  /*! Same function signature and usage as std::async(). Always launches the task in a parallel thread, using a thread
35  pool. Runs the task on little (ARM A53) cores when using big.little CPU architecture of JeVois Pro Platform, or on
36  the same thread pool as jevois::async() on other architectures. Use this function to run threads that are not very
37  compute intensive, e.g., threads that may sleep most of the time until some condition has become
38  satisfied. \ingroup utils */
39  template <class Function, class... Args>
40  [[nodiscard]] std::future<std::invoke_result_t<std::decay_t<Function>, std::decay_t<Args>...>>
41  async_little(Function && f, Args &&... args);
42 
43  //! Collect results from several async threads that are all returning a T result
44  /*! Guarantees that get() will run on all futures. If any throws, collect all the error messages (if possible, e.g.,
45  an std::exception was thrown) and assemble them into a single string of the form "[error 1][error 2] ..." or
46  "error 1\nerror 2\n...", then throw that as an std::runtime_error \ingroup utils */
47  template <typename T>
48  std::vector<T> joinall(std::vector<std::future<T>> & fvec, bool multiline = true);
49 
50  //! Collect results from several async threads that are all returning a T result
51  /*! Guarantees that get() will run on all futures. If any throws, collect all the error messages (if possible, e.g.,
52  an std::exception was thrown) and assemble them into a single string of the form "[error 1][error 2] ..." or
53  "error 1\nerror 2\n...", then throw that as an std::runtime_error \ingroup utils */
54  void joinall(std::vector<std::future<void>> & fvec, bool multiline = true);
55 
56 } // namespace jevois
57 
58 // Include implementation details:
59 #include <jevois/Util/details/AsyncImpl.H>
jevois::async
std::future< std::invoke_result_t< std::decay_t< Function >, std::decay_t< Args >... > > async(Function &&f, Args &&... args)
Async execution using a thread pool.
jevois
Definition: Concepts.dox:1
jevois::joinall
std::vector< T > joinall(std::vector< std::future< T >> &fvec, bool multiline=true)
Collect results from several async threads that are all returning a T result.
jevois::async_little
std::future< std::invoke_result_t< std::decay_t< Function >, std::decay_t< Args >... > > async_little(Function &&f, Args &&... args)
Async execution using a thread pool.