Re: [Boost-users] inheriting from boost::thread

I write a lot of cross-platform code that's used from JNI. In JNI, you
should tell the JVM about native threads that are running. Because Java
threads are named, when you attach a native thread to the JVM you have
to specify a name.
It occurred to me that I could write a "jnithread" class that inherits
from boost::thread. It would take a thread-name argument. Before the
threadfunc runs it would attach the new thread to the JVM, and when the
threadfunc ends it would detach from the JVM.
It's relatively easy to write such a class, and would make life easier
for thread creation within JNI. However, I hesitate because of the lack
of a virtual destructor...
-----Original Message-----
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of me22
Sent: Wednesday, September 21, 2005 1:27 PM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] inheriting from boost::thread
On 21/09/05, Simmons, Aaron
I've been thinking about writing a class that inherits from
boost::thread.
However, I noticed that the destructor isn't virtual. Shouldn't it be?
boost::thread is designed neither as a base class nor to be used polymorphically. Why do you want to inherit from a thread? You still couldn't get at the private thread handles and there are no virtual functions to modify behavior. - Scott _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Wed, 21 Sep 2005 15:39:35 -0300, Simmons, Aaron
I write a lot of cross-platform code that's used from JNI. In JNI, you should tell the JVM about native threads that are running. Because Java threads are named, when you attach a native thread to the JVM you have to specify a name.
It occurred to me that I could write a "jnithread" class that inherits from boost::thread. It would take a thread-name argument. Before the threadfunc runs it would attach the new thread to the JVM, and when the threadfunc ends it would detach from the JVM.
Why don't you write an adapter that takes a nullary function and calls it between attaches/dettaches. The syntax of creating a thread would then be: void worker_func(int i); thread mythread( jniadapt("mythread", bind(worker_func, 55)) ); Bruno
participants (2)
-
Bruno MartÃnez
-
Simmons, Aaron