C++ Programing for Financial Engineering Online Certificate. Join hundreds of graduates from over 35 countries on 5 continents.

Advanced C++11/C++14 and Multidisciplinary Applications Online Certificate. Launched in January 2017.

  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ Multithreading in Boost

Discussion in 'Computing' started by Daniel Duffy, 10/26/10.

  1. TkOp

    TkOp New Member

    Thank you for your enthusiasm ! I 've run code on section 18.11. My program is Visual Studio 2010.
    I recieved the following error:

    error C3861: 'IntToString': identifier not found
    left of '.c_str' must have class/struct/union1> type is ''unknown-type''

    Can you explain for me ?.I want to refer to it really work...Thank.
     
  2. Daniel Duffy

    Daniel Duffy C++ author, trainer
      C++ Level 1

    Code (C++):
    1. //    cout<<"Consumer "<<IntToString(m_id).c_str()<<" consumed: ("<<m_queue->Dequeue().c_str()<<")"<<endl;
    2.  
    3. Use:!!
    4.             std::cout << m_id << ", " << m_queue() << std::endl;
    You seem like a C++ novice (yes?) and PC pattern is very advanced.
     
  3. TkOp

    TkOp New Member

    I tried and still get same error.:cry:
    Actually, I'm new to multi-thread programing in C++ with Boost library.
    I want implement the following functionality :


    • There are 2 threads: producer and consumer.
    • Consumer only processes the firstest value, i.e., first in first out (FIFO).
    • using condition variable...

    Everything is hard for me. You can send me the complete code about Shared queue problem ?
    Thank.
     
  4. Daniel Duffy

    Daniel Duffy C++ author, trainer
      C++ Level 1

    It does work; I think you are doing something wrong.

    It's discussed in my Boost Volume I book.
     
  5. Daniel Duffy

    Daniel Duffy C++ author, trainer
      C++ Level 1

    Just comment out that cout line. Does the code work?
     
  6. TkOp

    TkOp New Member

    I 've run this code topic and get some error when running...
    error C3861: 'IntToString': identifier not found
    error C3861: 'IntToString': identifier not found
    error C2228: left of '.c_str' must have class/struct/union type is ''unknown-type''
    error C3861: 'IntToString': identifier not found

    Build FAILED.

    :cry:.I really tried to find out problem....Can you help me again.
    I really appreciate your help with my project!
     
  7. Daniel Duffy

    Daniel Duffy C++ author, trainer
      C++ Level 1

    Comment out EVERWHERE you have IntToString.
    Then?
     
  8. Daniel Duffy

    Daniel Duffy C++ author, trainer
      C++ Level 1

    Code (C++):
    1. template<typename T>
    2. std::string toString(const T& value)
    3. {
    4.     std::ostringstream oss;
    5.     oss << value;
    6.     return oss.str();
    7. }
    std::string IntToString (const int& i)
    {
    return toString<int>(i);
    }
     
  9. TkOp

    TkOp New Member

    :).It does work. Thanks a lot !
    I have to bother you with this problem.
     
    Daniel Duffy likes this.
  10. Ian Kaplan

    Ian Kaplan Active Member

    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
     
  11. Daniel Duffy

    Daniel Duffy C++ author, trainer
      C++ Level 1

    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
     
  12. Ian Kaplan

    Ian Kaplan Active Member

    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
     
  13. Daniel Duffy

    Daniel Duffy C++ author, trainer
      C++ Level 1

    #33 Daniel Duffy, 10/20/13
    Last edited: 10/20/13
  14. ExSan

    ExSan Active Member

    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.
     
  15. pingu

    pingu Well-Known Member

    do you mean OpenMP?
     
  16. ExSan

    ExSan Active Member

    yes