[Threads-list] no concurrency; my threads run sequentially!
Brought to you by:
hanseno
From: Shea M. <sh...@sh...> - 2002-02-01 21:40:27
|
1. Bug in install? I did a ./autogen, configure, make, make install. Programs compile fine, but can't execute b/c the can't find the libthreads.so. So I copied everything in the threads-3.5/src/.libs dir to /usr/lib. Now everything will execute. This is on Debian 3.0b. Now for the real problem. ================== This code compiles fine. It even executes fine with one thread. But if I try to create two threads, and then call each of their thread() methods, the two methods run sequentially. The two threads should be competing for the stdout, no? Thanks ~S #include <string> #include <iostream> #include <thread.h> using namespace std; using namespace cpp_threads; class Nums: public pthread { public: Nums(int id); int thread(void *); }; Nums::Nums(int id) :pthread(id) { cout <<"in constructor\n"; } int Nums::thread(void *) { for(int i=0; i < 100; i++) { cout <<"\n["<< id() <<"]->"<< i << endl; } } int main() { Nums num(5); Nums num2(99); cout <<"before starting the thread\n"; num.thread(NULL); <-----|--these should compete for the stdout num2.thread(NULL); <-----+ cout <<"after starting the thread\n"; cout <<"after starting the thread\n"; cout <<"after starting the thread\n"; cout <<"DONE\n"; return 0; } |