[omniORB] How to kill an omni_thread ???
Tristan Richardson
tjr@orl.co.uk
05 Nov 1998 10:19:47 +0000
"Andreas.Koehler" <koehler@vs.dasa.de> writes:
> using omniORB2 our pthread implementation should be substituted with
> omni_threads. One of the implemented functionality creates a pthread,
> waits for TIMEOUT seconds and will kill the pthread, if the pthread is
> still running after TIMEOUT seconds:
>
> pthread_t thr;
> pthread_attr_t attr;
> pthread_attr_init (&attr);
> pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
> if (pthread_create (&thr, &attr, <function_ptr>, <arg_ptr>)) {
> perror ("thread creation failed");
> kill (getpid (), SIGTERM); // terminating with implemented handler
> }
> ...
> pthread_kill(thr, SIGINT);
>
> Now we create an omni_thread with:
>
> omni_thread *thr;
> thr = omni_thread::create(<function_ptr>, <arg_ptr>);
>
> But what's the analogon to pthread_kill? Calling the destructor is not
> allowed!
There is intentionally no "thread kill" functionality in omnithread. For
all but the most trivial of cases (i.e. if the thread ever locks a mutex),
it is just about impossible to kill a thread like this without introducing
errors into your program. A thread should always be responsible for its own
destruction. If from another thread you want to tell a thread to exit then
you do this using the normal synchronisation primitives, and the thread
itself exits at a point where it can do so cleanly.
Cheers
Tristan
+-------------------------------------------------------------------------+
Tristan Richardson, ORL, 24a Trumpington Street, Cambridge, CB2 1QA, UK
tjr@orl.co.uk Tel: +44 1223 343000 Fax: +44 1223 313542
+-------------------------------------------------------------------------+
ORL - The Olivetti & Oracle Research Laboratory http://www.orl.co.uk
+-------------------------------------------------------------------------+