[omniORB] omniThread problem
Bjørn Kristian Larsen
bjorn.k.larsen at met.no
Thu Nov 13 18:07:24 GMT 2008
I got a segmentation-fault when trying to join omni_thread's to my main
thread. Both when using omni_thread::join() and omni_condition::wait ...
Is there anything logically wrong with my example?
Can i only call join() from another omni_thread?
class TestThread : public omni_thread {
public:
static int workingThreads;
private:
omni_condition& q_working;
int i, j, id, jd;
static omni_mutex * w_mutex;
public:
TestThread(int _i, int _j, omni_condition& working) :
omni_thread(), q_working(working)
{
i = id = _i;
j = jd = _j;
w_mutex->lock();
workingThreads ++;
w_mutex->unlock();
start_undetached();
}
//virtual void run(void* arg);
void* run_undetached(void* ptr) {
while(--i > 0) {
j = jd;
while(--j > 0){
int k = 100000;
while(--k > 0){
double d = (k%j) + (i%j) + (i%j) + (i%j);
}
}
cerr << id << ":" << i << ", ";
}
cerr << "done: " << id << endl;
w_mutex->lock();
workingThreads --;
w_mutex->unlock();
q_working.signal();
}
};
int TestThread::workingThreads = 0;
omni_mutex * TestThread::w_mutex = new omni_mutex();
int main(int argc, char *argv[]) {
cerr << "starting test" << endl;
omni_mutex mutex;
omni_condition condition(&mutex);
{
TestThread t1(1,300,condition);
TestThread t2(3,300,condition);
TestThread t3(4,300,condition);
TestThread t4(5,300,condition);
TestThread t5(6,300,condition);
TestThread t6(7,300,condition);
while(TestThread::workingThreads != 0){
cerr << "Waiting for " << TestThread::workingThreads << "
threads" << endl;
condition.wait();
}
}
cerr << "terminating test" << endl;
return 0;
}
More information about the omniORB-list
mailing list