On (02 Apr 97) Darin McBride wrote to Jerry Coffin...
JC> DWORD static __stdcall RealThreadProc(void *theClass) {
JC> // Here we invoke the virtual function in the class whose
JC> // address we passed into here...
JC> //
JC> return ((ThreadBase *)theClass)->ThreadProc();
JC> }
DM> Perhaps adding RTTI support to ensure we ARE dealing with a ThreadBase
DM> pointer here... :-)
It can't be done: you can't use RTTI on a pointer to void. RTTI has the
same problem you do at that point: it doesn't know enough about the
pointer to find out anything.
RTTI works perfectly well when you know you have a pointer to (at least)
a base class, and want to know whether it's really a pointer to a
derived class. However, to do that bit of magic, it follows the class'
vtable pointer back to the vtable, and looks at extra information the
compiler hides there, to check which sort of derived object it might be.
However, if what we have really isn't a pointer to the class at all,
then trying to find the vtable isn't going to work, and trying to look
at magic stuff the compiler hid in the vtable isn't going to work
either. If we have the wrong sort of pointer to start with, even the
attempt at using RTTI could very well get our program shut down.
JC> I'm not saving the thread ID, because it's pretty close to useless.
JC> I'm not even sure why they have thread IDs at all.
DM> I dunno about Win32, but I know that in OS/2 you can raise other
DM> thread's priorities, query their state (blocked, running, etc.), block
DM> them and, , kill them. (Mind you killing threads has the
DM> expected side effect of basically destabilizing the entire process and
DM> the entire process should then shut down immediately, preferably with
DM> a bit of grace.) All of this requires the thread ID.
Under Win32, most, if not all, of this involves the thread handle
instead of the ID.
DM> I'm pretty sure there is a fair bit of other stuff. (For example, in
DM> my semaphore objects, I need my thread ID in order to figure out if I
DM> am the thread who owns the semaphore or if it is someone else... I can
DM> then also figure out who it is so I can kill it )
Umm...I'm a bit lost as to what you're trying to get at here, though it
does give the glimmer of an idea of a use for the thread ID: it allows
you to identify the thread that owns something _without_ giving a thread
that receives it any other capabilities such as changing your priority,
killing you, etc.
(Those who've read Patricia McKillip might notice a rough parallel to
the "use name" vs. "true name" in some of her books. It always amazes
me how many parallels there are between programming and many of the
stories about magic. For those who don't understand a bit of what I'm
babbling about here, I'd reccomend reading _A Wizard of EarthSea_ -
quite good reading, IMO.)
Later,
Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)
|