[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Threads fail to join in 1.0.8
From: |
Jon Wilson |
Subject: |
Threads fail to join in 1.0.8 |
Date: |
Thu, 20 Mar 2003 17:34:52 +0000 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2.1) Gecko/20021130 |
I have some code (below) where I create two threads, they establish the
client and server ends of the socket and recieve a string append to it
and send it back. However, when the run method completes, the threads
call their finalize method and print as expected. However, in `main`,
the threads fail to join. Have I done something wrong? Is there a known
issue with this?
Thanks.
Jon Wilson
#include <cc++/thread.h>
#include <cc++/socket.h>
#include <iostream>
#include <sstream>
using namespace std;
using namespace ost;
class myThread : public Thread{
private:
bool read;
public:
myThread(bool read){
start();
this->read=read;
}
void final(){
cout << "Final" << endl;
}
void run(){
tcpstream* io;
if(read){
io=new tcpstream("127.0.0.1:9000");
}else{
TCPSocket tcp("127.0.0.1",9000);
while(!tcp.isPendingConnection());
io=new tcpstream(tcp);
cout << "Sent Hello" << endl;
*io << "Hello" << endl;
}
string s;
for(int i=0;i<100;i++){
cout << (read?"Read ":"Write ") << i << endl;
bool b;
do{
*io >> s;
b=!s.length();
if(b)Thread::yield();
}while(b);
ostringstream os;
os << s << i;
*io << os.str() << endl;
}
cout << s << endl;
io->close();
delete io;
}
};
int main(int argc,char** argv){
myThread t1(true);
myThread t2(false);
t1.join();
cout << "1 joined" << endl;
t2.join();
cout << "2 joined" << endl;
}
- Threads fail to join in 1.0.8,
Jon Wilson <=