[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with Thread::join()
From: |
Joan Carles Jimenez |
Subject: |
Problem with Thread::join() |
Date: |
Wed, 31 Oct 2007 23:30:54 +0100 |
User-agent: |
KMail/1.9.6 (enterprise 20070904.708012) |
Hi.
I have the next code:
#include <cc++/thread.h>
#include <stdio.h>
#include <stdlib.h>
using namespace ost;
class MyThread : public Thread {
public:
MyThread();
~MyThread();
public:
int a, b, p, ms;
double c;
static int runs;
private:
void run();
void final();
};
int MyThread::runs = 0;
MyThread::MyThread() {
}
MyThread::~MyThread() {
}
void MyThread::run() {
c = 0.0;
for(int i = a; i < b; i++) {
if(i % 2 == 0)
c = c + i;
else
c = c - i;
}
runs++;
//sleep(ms);
Thread::exit();
}
void MyThread::final() {
}
int main(void) {
MyThread *th1 = new MyThread();
th1->a = 1;
th1->b = 10000000;
th1->p = 1;
th1->ms = 1000;
MyThread *th2 = new MyThread();
th2->a = 1;
th2->b = 10000000;
th2->p = 2;
th2->ms = 500;
for(int i = 0; i < 1000; i++) {
int p1 = th1->start();
int p2 = th2->start();
th1->join();
th2->join();
}
fprintf(stdout, "-----> Runs %d\n", MyThread::runs);
delete th2;
delete th1;
return 0;
}
When I compile and execute the code, the "th1->join()" and "th2->join()" non
stop the threads. I use the commoncpp2 1.5.9 with openSUSE 10.3 64 bits. Can
you help me? Thanks.
Regards.
--
Joan Carles Jimenez
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Problem with Thread::join(),
Joan Carles Jimenez <=