[thread] - install - libraries not referencing?

I apologize if this question is asked frequently by noobs. Essentially,
the boost functions are not recognized. I installed the prebuilt boost
package on ubuntu (ostensibly 1.43), and wonder if it's working correctly.
I am working through the threading chapter from *Introduction to the C++
Boost Libraries – Volume I – Foundations,* and replicated their first
example:
#include

On Wed, 2011-12-07 at 19:39 +0200, floobit wrote:
using g++ boosttest1.c -o boosttest1
the compiler throws errors to each reference of a boost function (I have removed the names of temp files referenced by the compiler): undefined reference to `boost::this_thread::yield()' undefined reference to `boost::thread::~thread()'
Try g++ boosttest1.c -o boosttest1 -lboost_thread If you get more undefined references, try appending -lboost_system and/or -lpthread. Mika Heiskanen

Try
g++ boosttest1.c -o boosttest1 -lboost_thread
If you get more undefined references, try appending -lboost_system and/or -lpthread.
Thanks. The first extra argument solved the compilation issue, but I now get unexpected output (adding the suggested extra arguments does not help this). In particular, it seems that the second thread is not starting up, as I only get output from the main thread. The book says I should get a random interleaving of the lines outputted by each thread. My code:
void fxn1(){ for (int i=0; i<10; ++i){ cout << i << ") Do something in parallel with main method." << endl; boost::this_thread::yield(); }} int main(){ boost::thread t(&fxn1); for (int i=0;i<10; i++){ cout << i << ". Do something in main method." << endl; } return 0; } Thanks so much.

Thanks. The first extra argument solved the compilation issue, but I now get unexpected output (adding the suggested extra arguments does not help this). In particular, it seems that the second thread is not starting up, as I only get output from the main thread. The book says I should get a random interleaving of the lines outputted by each thread. My code:
void fxn1(){ for (int i=0; i<10; ++i){ cout << i << ") Do something in parallel with main method." << endl; boost::this_thread::yield(); }}
int main(){ boost::thread t(&fxn1); for (int i=0;i<10; i++){ cout << i << ". Do something in main method." << endl; } return 0; }
The second thread doens't have a chance to run. Try increasing the upper bound of the loops to one million or so.

A t.join() before the return in main will wait for the other thread to
finish executing before finishing the program.
On Wednesday, December 7, 2011, Igor R
Thanks. The first extra argument solved the compilation issue, but I now get unexpected output (adding the suggested extra arguments does not help this). In particular, it seems that the second thread is not starting up, as I only get output from the main thread. The book says I should get a random interleaving of the lines outputted by each thread. My code:
void fxn1(){ for (int i=0; i<10; ++i){ cout << i << ") Do something in parallel with main method." << endl; boost::this_thread::yield(); }}
int main(){ boost::thread t(&fxn1); for (int i=0;i<10; i++){ cout << i << ". Do something in main method." << endl; } return 0; }
The second thread doens't have a chance to run. Try increasing the upper bound of the loops to one million or so. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- - - - - - - - - - - - - - - - - - - - - *Nathan Currier*
participants (4)
-
floobit
-
Igor R
-
Mika Heiskanen
-
Nathan Currier