• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

C++ Multithreading in Boost

Code:
template<typename T>
std::string toString(const T& value)
{
    std::ostringstream oss;
    oss << value;
    return oss.str();
}

std::string IntToString (const int& i)
{
return toString<int>(i);
}
 
Code:
template<typename T>
std::string toString(const T& value)
{
    std::ostringstream oss;
    oss << value;
    return oss.str();
}

std::string IntToString (const int& i)
{
return toString<int>(i);
}

:).It does work. Thanks a lot !
I have to bother you with this problem.
 
Hi Daniel,

This is a great reference. It's clearly written and well explained. And the task is explaining the boost libraries.

In my opinion, however, the boost thread library is a horror. Doing simple things, like creating a threat class, is complex. In fact, almost everything that one might want to do is complex in the Boost thread library.

Instead of the Boost thread library, I highly recommend the Qt thread classes from the Qt Core. Most people think of Qt as a graphic library, which it is. But the Qt Core classes are very nice. And the Qt thread library is much like Java threading: easy to use and easy to understand (at least compared to the Boost thread library).

Best,

Ian
 
Hi Ian,
Boost thread (and C++ 11 concurrency) are very flexible but low-level indeed. We coded the producer-consumer a few years ago because they were no libraries for them and as a good test case.

QT is very good but I have not worked with it.

These days task libraries such as TBB, PPL and PPL hide low-level details and allow developers to think in parallel design patterns.

The book by Mattson et al 2005 gives a global overview of these patterns.

regards

Daniel
 
Thanks for the post, Daniel. As always you're very informative. I didn't know about the Intel Threading Building Block library. It looks interesting. I develop on Linux unless I have a compelling reason to use Windows, so PPL is not an option for me.

After I wrote that post about Qt I tried to get Qt to work on Linux (Fedora 14). I can't get the libraries right and I have found no documentation on what libraries I need to link with (other than Qt5Core). Its possible it's not compatible with the version of Linux/gcc I have, but I can't tell. So the TBB library looks like a good alternative now that I've reached a road block with Qt. Which is too bad. I've used Qt on Windows and I really like the class library.

One problem with Qt is that it uses its own allocation model, so you have to call a Qt initializer in main(). I'm fine using the STL or Boost containers. I just want object based threading. So I'd like something lighter weight than Qt and TBB looks like it might be what I'm looking for. It also looks like it supports loop level parallelism, which is not what I need right now. But I've used this in R, so I might want it in the future.

Best,
Ian
 
I have just got interested in this topic. I am using MS Express 2013
could some one post the code for Fibonacci ?

1. using threads ...// no boost please
2. using cores ...// #pragma

I would like to see the difference.

So far what I have learned is not so clear to me. Eager to learn. Thnkx.
 
This explanation was amazing and helped me very much! thanks!!
Thank you.
I wrote that article 10 years ago. The nice thing now is that threads (and tasks!) are supported in C++11 and porting code is more or less changing namespace boost to std.
 
Back
Top