question on THREADINIT

Bernie Solomon bernard at UG.EDS.COM
Tue Apr 15 01:50:33 PDT 1997


Andrew S Halper, Computer Specialist, Tucson, AZ wrote:
> 
> Hello,
> 
> I am in the process of attempting to port Kaffe to DG/UX m88k.  I'm
> almost done with the thread switching code, but I'm having difficulty
> understanding the THREADINIT macro.  Could someone briefly explain the
> general idea behind this bit of code?

Having had to look at this recently I'll submit my explanation.

A thread, when implemented using kaffe's internal threading, that is not
running typically has a special register save area at the "hot" end of
its stack which is what the thread context's restorePoint pointer points
at (restorePoint is typically a fixed offset from the stack pointer of
the suspended thread). The area contains registers and the PC to restore
to resume the thread wherever it was. If the thread switch is done by a
routine call rather than inline assembler the registers are typically
just the callee saved ones as the call to the thread switch routine
itself will save the caller saved ones that matter. Once the threads are
running this enables switching between them. However when a thread is
created for the first time somehow it needs to be started up. This is
done by the THREADINIT macro creating a register save area in the same
format which typically just leaves the registers uninitialised but sets
the PC to the entry point of the FUNC routine. When the scheduler
switches to that thread it will restore the registers and jump to the
routine FUNC's entry point (often firstStartThread except for GC
involved threads). The registers in this initial save area don't really
matter that much because the call to firstStartThread should never ever
return as it has nowhere to go to.

I hope this helps.

BTW Is everyone else getting recent postings three times? Has majordomo
got confused?
-- 
Bernie Solomon (bernard at edsug.com or Bernard.Solomon at acm.org)
Unigraphics Architecture, EDS-Unigraphics, Cambridge, UK



More information about the kaffe mailing list