Category : threadpool

I try to write my own version of a Thread pool but have difficulties with the line result.set_value(f(args…)); in : #ifndef THREADPOOL_HPP #define THREADPOOL_HPP #include <atomic> #include <functional> #include <future> #include <map> #include <mutex> #include <stack> #include <thread> #include <utility> #include <vector> class ThreadPool { public: ThreadPool(unsigned int thread = std::thread::hardware_concurrency(), unsigned int maxRecursionDepth=5): maxRecursion(maxRecursionDepth), ..

Read more

I can’t get this to work and I am fully out of ideas: for (auto& set : _physicsList) { _pool.push_back(std::thread{ Loop,std::ref(set) }); } physics list and pool are: std::vector < std::thread> _pool; std::vector < callbacklist > _physicsList; and are inited like so: _threadCounter = std::thread::hardware_concurrency(); if (_threadCounter == 0) _threadCounter += 2; else _pool = ..

Read more

I’m trying to pass a thread data structure which allocated for every thread PARAMS* params = (PARAMS*)malloc(_thread_count * sizeof(PARAMS)); structure contains some buffers allocated for each thread instead of allocating memory in function call for more performance struct PARAMS { unsigned char* inbuf, * outbuf, …; public: PARAMS() : inbuf(NULL), outbuf(NULL) {} }; the problem ..

Read more

I’m currently trying to extend the functionality of the NVIDIA CloudXR client app for HoloLens2 to perform ArUco marker tracking. The C++/WinRT app of the client app is initialized using MTA. The CloudXR functionality is provided using two .dlls. I’ve included the ArUco tracking capability in a separate Windows Runtime Component which the client app ..

Read more

I’m experimenting with boost::asio::thread_pool and helgrind reports errors in a simple program that has empty task function. Where is the problem and how can I fix it? #include <boost/thread/mutex.hpp> #include <boost/thread.hpp> #include <boost/asio/thread_pool.hpp> #include <boost/asio/post.hpp> int main() { ushort thread_num = 4; boost::asio::thread_pool pool(thread_num); auto task = []() {}; for (ushort i = 0; i ..

Read more

threadpool.h #ifndef THREADPOOL #define THREADPOOL #include <iostream> #include <thread> #include <vector> #include <mutex> #include <list> #include <condition_variable> template <typename T> class Threadpool { public: static int nums; Threadpool() : _threadSize(8), _queueMaxsize(100) { } Threadpool(int threadSize, int queueMaxsize) : _threadSize(threadSize), _queueMaxsize(queueMaxsize), m_stop(false) { for(int i=0; i<_threadSize; ++i) { threads.push_back(std::thread(worker,this,i)); } for (int i = 0; i ..

Read more

I made a script which calls some program via os.system() inside a ThreadPool and prints results of work to console. Simplified code looks this way: import os from concurrent.futures import ThreadPoolExecutor, as_completed import multiprocessing from threading import Lock print_mutex = Lock() def print_safe(text): with print_mutex: print(text, flush=True) def print_smth(): res = os.system("") print_safe("1") with ThreadPoolExecutor(max_workers ..

Read more