[fpc-pascal] Threading in FPC DOS

Marco van de Voort marcov at stack.nl
Wed Jul 12 09:29:54 CEST 2006

> >> I need to implement some simple threading in a DOS application I am 
> >> writing with FPC. What I need to know is the following:
> >>
> >> 1) Does FPC protect it's stack or can I allocate memory from the heap 
> >> and point SS and ESP to it for the threads stack.
> >>     
> >
> > I believe the latter is correct (except that no 
> > SS change should be needed), at least this is how 
> > it works for other targets as far as I know. 
> > Amount of memory to be allocated for stack is 
> > passed as a parameter during thread creation.
> >   
> Oh, so all the segments are the same in FPC? I mean CS = DS = SS? That 
> would really be swell.
> > BTW, in case you manage to create thread manager 
> > (systhrd.inc implementation) for GO32v2 target 
> > and are willing to share it with others, we'd be 
> > certainly interested to add it to FPC.
> >
> >   
> Hmm, I had thought to implement the TThread class. What is systhrd.inc? 
> It seems to be implemented with different methods for each target.

The includefile with the system dependant base for the tthread class. 

See how Unix does it  (unix/systhrd.inc and unix/cthreads.pp). Unix default
has threading disabled, but it is enabled if unit cthreads is included.

Since Dos can have multiple ways of multitasking (it could e.g. also plug in
to DV or Win3.x or TopView via int 2FH etc) this model seems advisable to me.

I assume you are implementing a basic fixed timeslicer?  What are you going
to use it for btw?  This because DV/X (which is free nowadays) afaik gives
you preemptive scheduling on Dos.

More information about the fpc-pascal mailing list