The examples often use std::cout inside tasks, and the output can get pretty jumbled.
For example, fig_3_03 output of
std::cout << "first node received: " << in << std::endl;
I've been changing these to, for example
`
std::stringstream ss;
ss << "first node received: " << in << std::endl;
std::cout << ss.str();
`
This seems to work, although it isn't clear to me that even it is guaranteed.
So, I'm adding a cout_locked function that should be guaranteed in my examples
`
tbb::spin_mutex mylock;
void cout_locked(const std::string &ss)
{
tbb::spin_mutex::scoped_lock smut(mylock);
std::cout << ss;
}
`
and so the code above becomes
`
std::stringstream ss;
ss << "first node received: " << in << std::endl;
//std::cout << ss.str();
cout_locked(ss.str());
`
The problem with the current output is easy to see if the fig_3_03 example is modified to send more messages in the test
`
// step 4: send messages
for (int i=0;i<100;i++)
my_first_node.try_put(i);
`
The examples often use std::cout inside tasks, and the output can get pretty jumbled.
For example, fig_3_03 output of
std::cout << "first node received: " << in << std::endl;I've been changing these to, for example
`
std::stringstream ss;
`
This seems to work, although it isn't clear to me that even it is guaranteed.
So, I'm adding a cout_locked function that should be guaranteed in my examples
`
tbb::spin_mutex mylock;
void cout_locked(const std::string &ss)
{
}
`
and so the code above becomes
`
std::stringstream ss;
`
The problem with the current output is easy to see if the fig_3_03 example is modified to send more messages in the test
`
// step 4: send messages
for (int i=0;i<100;i++)
my_first_node.try_put(i);
`