pthreads

joining a thread: “resource deadlock avoided”

帅比萌擦擦* 提交于 2020-07-27 03:34:59
问题 I use a c++ class that encapsulates a boost::asio::io_service . class IoService { public: static IoService& getInstance() { static IoService instance; return instance; } void start() { _ioServiceThread = std::thread(&IoService::run, this); } void stop() { _ioService.stop(); _ioServiceThread.join(); } void run() { _ioService.run(); } private: IoService(); ~IoService(); IoService(const IoService& old) = delete; IoService(const IoService&& old) = delete; IoService& operator=(const IoService& old

joining a thread: “resource deadlock avoided”

a 夏天 提交于 2020-07-27 03:32:45
问题 I use a c++ class that encapsulates a boost::asio::io_service . class IoService { public: static IoService& getInstance() { static IoService instance; return instance; } void start() { _ioServiceThread = std::thread(&IoService::run, this); } void stop() { _ioService.stop(); _ioServiceThread.join(); } void run() { _ioService.run(); } private: IoService(); ~IoService(); IoService(const IoService& old) = delete; IoService(const IoService&& old) = delete; IoService& operator=(const IoService& old

Why does GCC's threading standard library implementation throw exceptions if you don't include pthread?

a 夏天 提交于 2020-07-19 03:43:11
问题 When I write code that uses, for example, std::promise , and I don't include the PThread library in GCC, I get an exception thrown rather than a linker error. For example: void product(std::promise<int> intPromise, int a, int b) { intPromise.set_value(a * b); } int main() { int a = 20; int b = 10; std::promise<int> prodPromise; std::future<int> prodResult = prodPromise.get_future(); product(std::move(prodPromise), a, b); std::cout << "20*10= " << prodResult.get() << std::endl; } If I compile

Why does pclose return prematurely?

对着背影说爱祢 提交于 2020-07-09 17:13:43
问题 UPDATE 1: This question has been updated to eliminate the multithreading, simplifying its scope. The original problem popen ed in the main thread, and pclose d the child process in a different thread. The problem being asked about is reproducible much more simply, by doing the popen and pclose in the same (main) thread. Update 2: With help from responders at How to check libc version?, I think I've identified that the libc being used is uClibc 0.9.30. The following code popen s a script in

Why does pclose return prematurely?

拥有回忆 提交于 2020-07-09 17:13:42
问题 UPDATE 1: This question has been updated to eliminate the multithreading, simplifying its scope. The original problem popen ed in the main thread, and pclose d the child process in a different thread. The problem being asked about is reproducible much more simply, by doing the popen and pclose in the same (main) thread. Update 2: With help from responders at How to check libc version?, I think I've identified that the libc being used is uClibc 0.9.30. The following code popen s a script in

What is the best practice for passing data between threads? Queues, messages or others?

南楼画角 提交于 2020-07-04 08:03:47
问题 I got sensor data of various types that needs to be processed at different stages. From what I have read around, the most efficent way is to split the tasks into threads. Each puts the processed data into the entry queue of the next thread. So basically, a pipeline. The data can be quite large (a few Mbs) so it needs to be copied out of the sensor buffer and then passed along to the threads that will modify it and pass it along. I am interested in understanding the best way to do the passing.

How to set up pthreads on windows?

僤鯓⒐⒋嵵緔 提交于 2020-06-24 13:59:22
问题 I found an implementation for pthreads on Windows here, but I couldn't get it to work right. Can anyone help me to install pthreads ? Like where to put DLLs, .lib, and .h files? Also, as an environment I'm not using Visual Studio, but Codeblocks with Mingw. I usually develop on Linux, but this project has to be on Windows, and I've already got some code implemented using pthreads, so I don't want to use Windows Threads from 'windows.h'. 回答1: The .dll can go in any directory listed in your

How to set up pthreads on windows?

浪尽此生 提交于 2020-06-24 13:59:05
问题 I found an implementation for pthreads on Windows here, but I couldn't get it to work right. Can anyone help me to install pthreads ? Like where to put DLLs, .lib, and .h files? Also, as an environment I'm not using Visual Studio, but Codeblocks with Mingw. I usually develop on Linux, but this project has to be on Windows, and I've already got some code implemented using pthreads, so I don't want to use Windows Threads from 'windows.h'. 回答1: The .dll can go in any directory listed in your

ps display thread name

荒凉一梦 提交于 2020-06-24 08:49:10
问题 Is there a way for ps (or similar tool) to display the pthread's name? I wrote the following simple program: // th_name.c #include <stdio.h> #include <pthread.h> void * f1() { printf("f1 : Starting sleep\n"); sleep(30); printf("f1 : Done sleep\n"); } int main() { pthread_t f1_thread; pthread_create(&f1_thread, NULL, f1, NULL); pthread_setname_np(f1_thread, "f1_thread"); printf("Main : Starting sleep\n"); sleep(40); printf("Main : Done sleep\n"); return 0; } Is there a command/utility (like ps

Passing std::promise object to a function via direct function call

我是研究僧i 提交于 2020-06-16 02:59:50
问题 I am learning the std::promise and std::future in C++. I wrote one simple program to calculate the multiplication of two numbers. void product(std::promise<int> intPromise, int a, int b) { intPromise.set_value(a * b); } int main() { int a = 20; int b = 10; std::promise<int> prodPromise; std::future<int> prodResult = prodPromise.get_future(); // std::thread t{product, std::move(prodPromise), a, b}; product(std::move(prodPromise), a, b); std::cout << "20*10= " << prodResult.get() << std::endl;