#### TkOp

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

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.

#### Daniel Duffy

##### C++ author, trainer
C++:
//    cout<<"Consumer "<<IntToString(m_id).c_str()<<" consumed: ("<<m_queue->Dequeue().c_str()<<")"<<endl;

Use:!!
std::cout << m_id << ", " << m_queue() << std::endl;

You seem like a C++ novice (yes?) and PC pattern is very advanced.

#### TkOp

C++:
//    cout<<"Consumer "<<IntToString(m_id).c_str()<<" consumed: ("<<m_queue->Dequeue().c_str()<<")"<<endl;

Use:!!
std::cout << m_id << ", " << m_queue() << std::endl;

You seem like a C++ novice (yes?) and PC pattern is very advanced.
I tried and still get same error.
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.

#### Daniel Duffy

##### C++ author, trainer
It does work; I think you are doing something wrong.

It's discussed in my Boost Volume I book.

#### Daniel Duffy

##### C++ author, trainer
Just comment out that cout line. Does the code work?

#### TkOp

Just comment out that cout line. Does the code work?
I 've run this code topic and get some error when running...
error C2228: left of '.c_str' must have class/struct/union type is ''unknown-type''

Build FAILED.

.I really tried to find out problem....Can you help me again.
I really appreciate your help with my project!

#### Daniel Duffy

##### C++ author, trainer
Comment out EVERWHERE you have IntToString.
Then?

#### Daniel Duffy

##### C++ author, trainer
C++:
template<typename T>
std::string toString(const T& value)
{
std::ostringstream oss;
oss << value;
return oss.str();
}

std::string IntToString (const int& i)
{
}

#### TkOp

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

std::string IntToString (const int& i)
{
}

.It does work. Thanks a lot !
I have to bother you with this problem.

#### Ian Kaplan

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

#### Daniel Duffy

##### C++ author, trainer
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

#### Ian Kaplan

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

#### ExSan

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

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.

#### CaTx

I sign up for an account here just to thank you for this excellent article, Mr. Duffy.

#### CaTx

Oh well, I figured it out.

Last edited:

Replies
8
Views
4K
Replies
4
Views
2K
Replies
7
Views
36K
Replies
15
Views
20K
Replies
4
Views
6K