boost-thread

C++ gettid() was not declared in this scope

故事扮演 提交于 2019-12-03 07:26:37
问题 A simple program is: I would like to get the thread ID of both of the threads using this gettid function. I do not want to do the sysCall directly. I want to use this function. #include <iostream> #include <boost/thread/thread.hpp> #include <boost/date_time/date.hpp> #include <unistd.h> #include <sys/types.h> using namespace boost; using namespace std; boost::thread thread_obj; boost::thread thread_obj1; void func(void) { char x; cout << "enter y to interrupt" << endl; cin >> x; pid_t tid =

Creating a boost::thread with boost::bind() or without

让人想犯罪 __ 提交于 2019-12-03 06:18:09
Some people seem to launch boost::threads using the boost::bind() function, like in the accepted answer of the following question: Using boost thread and a non-static class function Whereas other people don't use it at all, like in the answer with the most upvotes of this question: Best way to start a thread as a member of a C++ class? So, what's the difference, if it exists? As you can see by the code below that compile and gives the expected output, boost::bind is completely unnecessary for using boost::thread with free functions, member functions and static member functions: #include <boost

false sharing in boost::detail::spinlock_pool?

巧了我就是萌 提交于 2019-12-03 05:54:50
问题 I came across this SO question and reading it over eventually led me to look at boost::detail::spinlock_pool . The purpose of boost::detail::spinlock_pool is to reduce potential contention for a global spinlock by choosing from an array of spinlock s by hashing over the shared_ptr 's address. This seems like a reasonable solution but there seems to be a problem with the current (Boost v1.49) version's implementation. spinlock_pool manages a statically allocated array of 41 spinlock instances.

What's the difference between “mutex” and “lock”?

Deadly 提交于 2019-12-03 05:44:00
问题 I am very confused about the difference between a lock and mutex. In Boost docs, it says, Lock Types Class template lock_guard Class template unique_lock Class template shared_lock Class template upgrade_lock Class template upgrade_to_unique_lock Mutex-specific class scoped_try_lock Mutex Types Class mutex Typedef try_mutex Class timed_mutex Class recursive_mutex Typedef recursive_try_mutex Class recursive_timed_mutex Class shared_mutex In another article, I see functions like this, boost:

(simple) boost thread_group question

好久不见. 提交于 2019-12-03 05:41:48
问题 I'm trying to write a fairly simple threaded application, but am new to boost's thread library. A simple test program I'm working on is: #include <iostream> #include <boost/thread.hpp> int result = 0; boost::mutex result_mutex; boost::thread_group g; void threaded_function(int i) { for(; i < 100000; ++i) {} { boost::mutex::scoped_lock lock(result_mutex); result += i; } } int main(int argc, char* argv[]) { using namespace std; // launch three threads boost::thread t1(threaded_function, 10);

Is it expected that use of boost::thread_specific_ptr<>::get() be slow? Any work arounds?

蓝咒 提交于 2019-12-03 05:35:23
I'm currently profiling an application with performance problems using Valgrind's "Callgrind". In looking at the profiling data, it appears that a good 25% of processing time is being spent inside of boost::detail::get_tss_data in an application whose primary purpose is physics simulation and visualization. get_tss_data is apparently called by thread_specific_ptr::get Does anyone see this as expected? Does it generally imply something else specific? Edit: My platform is: Linux-2.6.32, x86, GCC 4.4.3, libc6-2.11.1/libpthread-2.11.1 thread_specific_ptr uses pthread_setspecific / pthread

Boost thread error: undefined reference

半世苍凉 提交于 2019-12-03 04:15:41
问题 #include <boost/thread/thread.hpp> #include <iostream> void hello() { std::cout << "Hello world, I'm a thread!" << std::endl; } int main(int argc, char* argv[]) { boost::thread thrd(&hello); thrd.join(); return 0; } I ran tried to compile this program, and got these errors: /usr/include/boost/thread/pthread/mutex.hpp:40: undefined reference to `boost::thread_resource_error::thread_resource_error()' /usr/include/boost/thread/pthread/mutex.hpp:40: undefined reference to `boost::thread_resource

C++ gettid() was not declared in this scope

二次信任 提交于 2019-12-02 20:57:06
A simple program is: I would like to get the thread ID of both of the threads using this gettid function. I do not want to do the sysCall directly. I want to use this function. #include <iostream> #include <boost/thread/thread.hpp> #include <boost/date_time/date.hpp> #include <unistd.h> #include <sys/types.h> using namespace boost; using namespace std; boost::thread thread_obj; boost::thread thread_obj1; void func(void) { char x; cout << "enter y to interrupt" << endl; cin >> x; pid_t tid = gettid(); cout << "tid:" << tid << endl; if (x == 'y') { cout << "x = 'y'" << endl; cout << "thread

Boost 1.49 Condition Variable issue

老子叫甜甜 提交于 2019-12-02 19:55:53
问题 I am trying to use Boost Conditional variable in my application to synchronize two different threads as following: The main thread, will create a TCP server and instance of object called MIH-User and register a callback to an event_handler. Main.cpp /** * Default MIH event handler. * * @param msg Received message. * @param ec Error code. */ void event_handler(odtone::mih::message &msg, const boost::system::error_code &ec) { if (ec) { log_(0, __FUNCTION__, " error: ", ec.message()); return; }

false sharing in boost::detail::spinlock_pool?

北城以北 提交于 2019-12-02 19:18:49
I came across this SO question and reading it over eventually led me to look at boost::detail::spinlock_pool . The purpose of boost::detail::spinlock_pool is to reduce potential contention for a global spinlock by choosing from an array of spinlock s by hashing over the shared_ptr 's address. This seems like a reasonable solution but there seems to be a problem with the current (Boost v1.49) version's implementation. spinlock_pool manages a statically allocated array of 41 spinlock instances. It appears that sizeof(spinlock)==4 for the platforms I looked at -- which means on, say x64 with 64