[omniORB] omnithread problem
Kelly Burkhart
kburk@sky.net
Wed, 11 Aug 1999 23:25:43 -0500 (CDT)
I have run accross a problem subclassing omni_thread. If I create a
mutex and a condition variable within a subclass of omni_thread, and
do a omni_condition::timedwait, then an omni_thread_fatal exception is
thrown from the mutex destructor.
The following program illustrates. Commenting out the mutex delete
(line 22) or commenting out the timed wait (line 34) will allow the
program to run to completion. With both of these lines in effect, an
exception will be thrown and caught in the destructor.
Here are the commands I used to compile and link (lines broken with
backslash):
g++ -pthread -c -Wall -W -g3 -Wno-unused -D__x86__ -D__linux__ \
-D__OSVERSION__=2 -I/usr/local/omniorb/include -o othread.o othread.cpp
g++ -o othread othread.o -L/usr/local/omniorb/lib -lomnithread -lpthread
Here is the system info:
RedHat 5.1
$ gcc -v
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
binutils-2.9.1.0.19a-1
glibc-devel-2.0.7-29
glibc-2.0.7-29
Linux version 2.0.34 (root@porky.redhat.com) (gcc version 2.7.2.3) #1 Fri May 8 16:05:57 EDT 1998
Here is the program:
#include <string.h>
#include <iostream.h>
#include <time.h>
#include "omnithread.h"
class SubThread : public omni_thread {
public:
SubThread() : omni_thread(), mux_(0), cond_(0) {
mux_ = new omni_mutex();
cond_ = new omni_condition( mux_ );
start();
}
private:
omni_mutex *mux_;
omni_condition *cond_;
virtual ~SubThread() {
try {
delete cond_;
delete mux_;
cout << "deleting!\n";
} catch( const omni_thread_fatal &ex ) {
cout << "caught a fatal omni thread exception! errno = " << ex.error << endl;
cout << "\t" << strerror( ex.error ) << endl;
}
}
virtual void run( void * ) {
cout << "running!\n";
unsigned long as1, ans1;
get_time( &as1, &ans1, 1, 0 );
cond_->timedwait( as1, ans1 );
return;
}
// Don't use these!
SubThread( const SubThread & );
SubThread &operator=( const SubThread & );
};
int
main()
{
SubThread *smt = new SubThread();
sleep(2);
return 0;
}