[futurebasic] Enterproc FN

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 1999 : Group Archive : Group : All Groups

From: "Dr. Steven J. Stratford" <sstratford@...>
Date: Wed, 22 Sep 1999 21:45:55 -0500
This may be one for Andy to take a look at.

I'm working on getting threading to work in FB^3 for my Threaded ACGI 
Framework, and I think I'm close but I've hit a "guts of the machine" 
snag. Here's the relevant part of my Tlbx Threads.INCL, the way I 
think the TOOLBOX calls should look in FB^3. I'm pretty sure I have 
the LONG's and WORD's right (see pascal header code below), and I'm 
sure the library PPC code is getting called. (I'm only concerned with 
compiling PPC code right now, but I think the assembly codes are 
right, too.)

LIBRARY "ThreadsLib"
WORD `0x303C,0x0E03,0xABF2
TOOLBOX FN DisposeThread(LONG, LONG, WORD) = WORD `0x303C,0x0504,0xABF2
TOOLBOX FN YieldToAnyThread = WORD `0x42A7,0x303C,0x0205,0xABF2
Here are the pascal headers:

FUNCTION NewThread(threadStyle: ThreadStyle; threadEntry: 
ThreadEntryProcPtr; threadParam: LONGINT; stackSize: Size; options: 
ThreadOptions; threadResult: LongIntPtr; VAR threadMade: 
     INLINE $303C,$0E03,$ABF2;

FUNCTION DisposeThread(threadToDump: ThreadID; threadResult: LONGINT; 
recycleThread: BOOLEAN):OSErr;
     INLINE $303C,$0504,$ABF2;

FUNCTION YieldToAnyThread:OSErr;
     INLINE $42A7,$303C,$0205,$ABF2;
My main program sets up a new thread, which is handed a procptr 
(procptr& = PROC "THREADHANDLERENTRY") in the second parameter. Then 
the main program calls YieldToAnyThread, at which time the OS Thread 
Manager transfer control to the thread handler entry proc ptr, which 
is at an ENTERPROC. This calls my ThreadHandler function, which does 
its thing and eventually disposes of the thread. Here's what's at 

ENTERPROC FN ThreadHandlerEntry (myThreadData&)
FN ThreadHandler(myThreadData&)'ThreadHandler is prototyped above
(in FBII I had:
ENTERPROC (gThreadParam&)
   GOSUB "THandler"
EXITPROC and it worked magnificently.)
The call to NewThread comes back with no error so that's ok. I 
dropped into macsbug just before YieldToAnyThread and by the looks, 
the thread manager is swapping registers for the new thread just like 
it should, so I'm reasonably sure the new thread is there waiting for 
activation. But I'm getting a consistent "PowerPC Access exception at 
AAFE0700" after YieldToAnyThread. When I disassemble the code at 
THREADHANDLERENTRY, the first opcode is a "b" with a FCOD 
...FB^3.PPC'... to the right, and the second opcode is "lha 
r23,0x0700(r30) | AAFE0700". That last number catches my attention 
because it's the same address that keeps coming up in the PPC 
exception. However at that point my ignorance of PPC assembler stops 
me cold. Any idea what I may be doing wrong? Thanks for your help.


Steven J. Stratford, InterNetyx.com
Supercharge your website!