[fpc-pascal] Threading in FPC DOS

Tomas Hajny XHajT03 at mbox.vol.cz
Wed Jul 12 11:15:05 CEST 2006


Marco van de Voort wrote:
>> >> 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.

You certainly cannot rely on CS being the same as the other two. It points
to the same address space, but possibly using different selector to allow
different access rights (no write access to CS).


>> > 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.


Well, multitasking <> multithreading. I'm not sure if DV or Win 3.x
provide special multithreading support for DOS applications... In contrary
to Marco's suggestion, I can imagine the multithreading support could be
general and included by default for GO32v2 (similarly to Win32). However,
it certainly depends on whether a general solution (not requiring special
support like DV, etc.) is really feasible and practical.

Tomas




More information about the fpc-pascal mailing list