boost-thread

is std::queue thread safe with producer and multiple consumers

萝らか妹 提交于 2019-12-19 05:15:30
问题 how can I make a queue thread safe? I need to push / pop / front / back and clear. is there something similar in boost? I have one producer and one or more consumer. 回答1: You must protect access to std::queue . If you are using boost protect it using boost::mutex . Now if you have multiple readers and one writer thread look at boost::shared_lock (for readers) and boost::unique_lock (for writer). However if you will encounter writer thread starvation look at boost::shared_mutex . 回答2: std:

why is string not declared in scope

老子叫甜甜 提交于 2019-12-18 12:49:31
问题 I have the following code: #include <string> #include <boost/thread/tss.hpp> static boost::thread_specific_ptr<string> _tssThreadNameSptr; I get the following error g++ -c -I$BOOST_PATH tssNaming.h tssNaming.h:7: error: 'string' was not declared in this scope But I am including string in my #include . 回答1: You have to use std::string since it's in the std namespace. 回答2: string is in the std namespace. You have the following options: Write using namespace std; after the include and enable all

CMake and Boost

不羁岁月 提交于 2019-12-18 12:08:11
问题 I've searched and found out that a lot of people have the same problem, but no solution exists. I'm using CMake to generate Makefiles for MinGW and when compiling I'm getting an error: CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x5e): undefined reference to `_imp___ZN5boost6thread4joinEv' CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x71): undefined reference to `_imp___ZN5boost6threadD1Ev' CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(

Is there a bug in the boost asio HTTP Server 3 example or boost bug?

风流意气都作罢 提交于 2019-12-18 09:11:15
问题 boost library version 1.53 Debian Linux 6.0 ( Linux 2.6.32-5-amd64 on x86_64 ) It is hard to test own software when valgrind log contains lots of warnings. So with no changes I built the HTTP server3 example and run it under the Valgrind. Take a look, please. Did I miss something? valgrind --tool=helgrind --log-file=valgrind.log ./server3 0.0.0.0 83 5 /root/server3 Here is the Helgrind log (edited to 30000 body characters limit, full log http://pastebin.com/Vkbr9vsA): Helgrind, a thread error

Boost.Thread Linking - boost_thread vs. boost_thread-mt

ぐ巨炮叔叔 提交于 2019-12-18 03:54:56
问题 It's not clear to me what linking options exist for the Boost.Thread 1.34.1 library. I'm on Ubuntu 8.04 and I've found that when using either boost_thread or boost_thread-mt during linking both compile and run, but I don't see any documentation on these or any other linking options in above link. What Boost.Thread linking options are available and what do they mean? 回答1: Well... The first amusing thing is that the -mt modifier in the name is to indicate the library is Ok for multithreading.

Can multithreading speed up memory allocation?

笑着哭i 提交于 2019-12-17 15:39:55
问题 I'm working with an 8 core processor, and am using Boost threads to run a large program. Logically, the program can be split into groups, where each group is run by a thread. Inside each group, some classes invoke the 'new' operator a total of 10000 times. Rational Quantify shows that the 'new' memory allocation is taking up the maximum processing time when the program runs, and is slowing down the entire program. One way I can speed up the system could be to use threads inside each 'group',

Creating a thread pool using boost

 ̄綄美尐妖づ 提交于 2019-12-17 08:59:26
问题 Is it possible to create a thread pool using boost's thread? i was looking all over boost's libs and I couldn't find a thread pool manager (or something like that)... Is there a way to do it? tnx! 回答1: There is an unofficial (yet) threadpool in boost. But it's not a problem to implement one yourself especially if great genericity is not a primary goal. Idea: your threadpool can be parametrized with TaskType type and the number of workers. The TP must be given the handler function which takes

How to create a thread pool using boost in C++?

旧巷老猫 提交于 2019-12-17 00:47:52
问题 How do I create a thread pool using boost in C++, and how do I assign tasks to the threadpool? 回答1: The process is pretty simple. First create an asio::io_service and a thread_group. Fill the thread_group with threads linked to the io_service. Assign tasks to the threads using the boost::bind function. To stop the threads (usually when you are exiting your program) just stop the io_service and join all threads. You should only need these headers: #include <boost/asio/io_service.hpp> #include

How to create a thread pool using boost in C++?

霸气de小男生 提交于 2019-12-17 00:47:23
问题 How do I create a thread pool using boost in C++, and how do I assign tasks to the threadpool? 回答1: The process is pretty simple. First create an asio::io_service and a thread_group. Fill the thread_group with threads linked to the io_service. Assign tasks to the threads using the boost::bind function. To stop the threads (usually when you are exiting your program) just stop the io_service and join all threads. You should only need these headers: #include <boost/asio/io_service.hpp> #include

boost asio need to post n jobs only after m jobs have finished

梦想的初衷 提交于 2019-12-14 02:43:22
问题 I'm looking for a way to wait for a number of jobs to finish, and then execute another completely different number of jobs. With threads, of course. A brief explanation: I created two worker threads, both executing run on io_service. The code below is taken from here. For the sake of simplicity, i had created two types of jobs, CalculateFib i CalculateFib2 . I want the CalculateFib2 jobs to start after and only after the CalculateFib jobs finish. I tried to use condition variable as explained