Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2013-09

Multithreading under DOS (was: Why development remains constant for msdos?)

59 messages · 15 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Nikolay Nikolov
Mark Morgan Lloyd wrote 41 lines
Nikolay Nikolov wrote: > On 09/25/2013 11:26 AM, Michael Schnell wrote: >> On 09/24/2013 10:58 AM, Nikolay Nikolov wrote: >>> >>> When you try to create a thread, your program terminates and writes >>> a message that threading is not supported. >> >> While this absolutely does make sense, one could think about >> alternatives. >> >> AFAIK, (at least for some archs) there is a variant of the pthread >> (="POSIX thread") library, that internally does "user-land >> multithreading". IIRC, the original POSIX definition was done with >> exactly this in mind and, regarding Linux, the original Linux >> implementations (aka "Linux Threads") was not fully compatible with >> POSIX. Only some years ago, the Linux changed it's way of >> Kernel-based thread handling to the POSIX compatible "NPTL" >> implementation. >> >> Thus it should be possible to link fpc projects to a user-land >> thread enabled version of pthreadlib and allow for working with >> TThread in DOS. > > I've actually thought about implementing some sort of multithreading > for DOS for a long time. The problems are the following: > > 1) DOS functions are not reetrant and are thus not safe to call from > different threads. There's an undocumented InDOS flag that indicates > whether a DOS function is safe to call: > > http://stanislavs.org/helppc/int_21-34.html > > But the RTL currently doesn't check it before every call and normally > it's only used when writing TSRs. It's more complex than that: there's undocumented provision in DOS for context switching under certain well-defined conditions, and each context can invoke int 21h irrespective of other contexts' states. That sort of thing was used fairly extensively by- for example- IBM real-time control executives (RIC card etc.) but it wasn't until the 1990s that it leaked to general knowledge see Ralph Brown's list).

Interesting. I didn't know that. That makes it even more feasible to try to implement multithreading under real mode DOS.

Show quoted text 34 lines
> 2) In DPMI protected mode applications (such as go32v2), you cannot > modify the return address from within an interrupt handler, which > means you cannot implement your task scheduler as a timer interrupt > handler, because you won't be able to switch to a different context > from there. Doing this would require modifications to the DPMI host > (cwsdpmi.exe) and will not work if another DPMI host is active (such > as when running in a windows dos prompt, etc.) > > 3) Even if you solve 2), DPMI requires that all code and data touched > from an interrupt handler to be locked, so that it cannot be swapped > out. This is a tedious and error prone task to do from a high level > language such as pascal. You should ensure that your entire > scheduler's code and data are locked. An alternative option is to > switch to a DPMI host, that doesn't support swapping (i.e. > cwsdpr0.exe), but then you lose the virtual memory support (and thus > the ability to run on machines that don't have enough memory). > > 2) and 3) do not apply to 16-bit MS-DOS. > > Another option is to implement cooperative multitasking, which would > require each thread to call periodically an yield function. This > solves 1), 2) and 3), but threaded code written for other OSes will > require modifications to run under DOS. However, that's still better > than not running at all. The DPMI issue sounds... interesting, but if I recall correctly what you do is provide a per-thread entry point analogous to a unix signal. A preemption interrupt transfers control to this, and then a coroutine mechanism- outside the ISR- transfers control to the most deserving thread. Sorry if that's a bit vague, it's been many years since I played with this. Implementation left as an exercise :-)

Yes, but the problem is, when the ISR occurs, you cannot transfer control to this per-thread entry point, because when a hardware interrupt occurs, the return address is actually in a hidden ring 0 stack and you don't have access to it. You can probably do it with a known DPMI host, that runs your program in ring 0, such as cwsdpr0.exe.

Whether it's really worth tackling, and whether any implementation can be really reliable, are questions to be considered.

It's worth for the fun factor for me at least :) As for reliability, I bet you can make it as reliable as Windows 98 was at the time, which is not that great, as we all know, but still quite usable.

Oh, and before I forget, later versions of DR-DOS have a version of emm386.exe which supports multitasking and has an API that supports creating processes and threads (from both real and dpmi protected mode) :

http://www.drdos.net/documentation/multtask/

This should be easy to implement under both i386-go32v2 and i8086-msdos. Since the FPC rtl has support for pluggable thread managers, it can be put in a unit like cthreads.

Nikolay

Reply by email

Tomas Hajny
to Nikolay Nikolov
Nikolay Nikolov wrote 10 lines
On 09/25/2013 01:45 PM, Mark Morgan Lloyd wrote: > Nikolay Nikolov wrote: >> On 09/25/2013 11:26 AM, Michael Schnell wrote: >>> On 09/24/2013 10:58 AM, Nikolay Nikolov wrote: >>>> >>>> When you try to create a thread, your program terminates and writes >>>> a message that threading is not supported. >>> >>> While this absolutely does make sense, one could think about >>> alternatives.

.
.

Show quoted text 20 lines
>> I've actually thought about implementing some sort of multithreading >> for DOS for a long time. The problems are the following: >> >> 1) DOS functions are not reetrant and are thus not safe to call from >> different threads. There's an undocumented InDOS flag that indicates >> whether a DOS function is safe to call: >> >> http://stanislavs.org/helppc/int_21-34.html >> >> But the RTL currently doesn't check it before every call and normally >> it's only used when writing TSRs. > > It's more complex than that: there's undocumented provision in DOS for > context switching under certain well-defined conditions, and each > context can invoke int 21h irrespective of other contexts' states. > That sort of thing was used fairly extensively by- for example- IBM > real-time control executives (RIC card etc.) but it wasn't until the > 1990s that it leaked to general knowledge see Ralph Brown's list). Interesting. I didn't know that. That makes it even more feasible to try to implement multithreading under real mode DOS.

In addition to the InDOS flag, DOS int 21h, AX=5D06h suggests some options for addressing this topic too.

.
.

Show quoted text 16 lines
> Whether it's really worth tackling, and whether any implementation can > be really reliable, are questions to be considered. > It's worth for the fun factor for me at least :) As for reliability, I bet you can make it as reliable as Windows 98 was at the time, which is not that great, as we all know, but still quite usable. Oh, and before I forget, later versions of DR-DOS have a version of emm386.exe which supports multitasking and has an API that supports creating processes and threads (from both real and dpmi protected mode) : http://www.drdos.net/documentation/multtask/ This should be easy to implement under both i386-go32v2 and i8086-msdos. Since the FPC rtl has support for pluggable thread managers, it can be put in a unit like cthreads.

Anyway, interesting thread. ;-) Still, the overall goal (or set of goals) is not clear for me from the limited context included:

If the goal is writing multi-threaded applications for existing pure DOS machines, then using features of a special DR-DOS version may not be relevant at all, because it imposes a considerable additional restriction (it is not like that potential applications developed this way may be simply run under the existing installations, but users would need to install this particular version first).

If the goal is running light-weight multi-threaded FPC-compiled applications on old/weak hardware using free operating systems (which may need to be installed to support this application - as it would be the case with DR-DOS too), then there are probably better options (e.g. some fine-tuned Linux distribution).

If the goal is converting previously existing TP/BP applications written for DOS to become multi-threaded, porting to a different target is probably still easier, because the multi-threaded design will require changes to the application anyway.

If the goal is just having some fun with low-level programming - OK, understood; I would know some some other fairly low-level challenges, but the fun factor of different topics is obviously purely individual.

Tomas

Reply by email

Michael Schnell
to Tomas Hajny
Tomas Hajny wrote
Anyway, interesting thread. ;-) Still, the overall goal (or set of goals) is not clear for me

My intention with this was the (original) POSIX thread definition, that (IIRC) does not require or rely on an external OS that (besides multitasking multiple applications) helps with implementing multithreading within an application.

Here the old style ("light weight" / "internal" multi-thread enabled) pthread lib might help. Supposedly same does not need to be "installed" but could be statically linked to.

(But don't ask me where such a beast can be found...)

Supposedly same only comes in 32 Bit flavor, thus a DOS extender or GO32 will be necessary to run such programs.

-Michael

Reply by email

Frederic Da Vitoria
to Tomas Hajny: . . In addition to the InDOS flag, DOS int 21h, AX=5D06h suggests some options for…

2013/9/25 Tomas Hajny

Show quoted text 18 lines
If the goal is writing multi-threaded applications for existing pure DOS machines, then using features of a special DR-DOS version may not be relevant at all, because it imposes a considerable additional restriction (it is not like that potential applications developed this way may be simply run under the existing installations, but users would need to install this particular version first). If the goal is running light-weight multi-threaded FPC-compiled applications on old/weak hardware using free operating systems (which may need to be installed to support this application - as it would be the case with DR-DOS too), then there are probably better options (e.g. some fine-tuned Linux distribution). If the goal is converting previously existing TP/BP applications written for DOS to become multi-threaded, porting to a different target is probably still easier, because the multi-threaded design will require changes to the application anyway.

If the fpc application is completely alone, you are probably right (although you should also take into account learning linux, which may not be easy for everybody). But the fpc application could be part of an existing set of applications, in which case changing the OS could be impossible. This is a purely theoretical observation, I haven't developed for PC/MS-DOS or been using it for years.

Frederic Da Vitoria (davitof) Membre de l'April - « promouvoir et défendre le logiciel libre » - http://www.april.org

Reply by email

Tomas Hajny
to Michael Schnell: My intention with this was the (original) POSIX thread definition, that (IIRC) does not…
Michael Schnell wrote 8 lines
On 09/25/2013 07:13 PM, Tomas Hajny wrote: > Anyway, interesting thread. ;-) Still, the overall goal (or set of > goals) is not clear for me My intention with this was the (original) POSIX thread definition, that (IIRC) does not require or rely on an external OS that (besides multitasking multiple applications) helps with implementing multithreading within an application.

Well, there are certain assumptions for the POSIX thread definition regarding the underlying operating system - e.g. compliancy of the underlying operating system to other parts of POSIX (which is certainly not fulfilled in case of DOS).

Here the old style ("light weight" / "internal" multi-thread enabled) pthread lib might help. Supposedly same does not need to be "installed" but could be statically linked to.

You can run another operating system on top of DOS (that's basically what DOS extenders did), but you still need to find the solution first (and the solution is not the "POSIX threads library", but the "extender").

Tomas

Reply by email

Bernd Oppolzer
to Tomas Hajny
Tomas Hajny wrote 9 lines
> Here the old style ("light weight" / "internal" multi-thread enabled) > pthread lib might help. Supposedly same does not need to be "installed" > but could be statically linked to. You can run another operating system on top of DOS (that's basically what DOS extenders did), but you still need to find the solution first (and the solution is not the "POSIX threads library", but the "extender"). Tomas

I believe that DOS from its design is so limited that the only solution is what OS/2 did: isolate every DOS session and give it an own - single threaded - copy of a virtual machine, where DOS can run the old DOS applications.

The POSIX threads should be moved to or implemented on "real" operating systems.

Reply by email

Michael Schnell
to Tomas Hajny: Well, there are certain assumptions for the POSIX thread definition regarding the…
Tomas Hajny wrote
Well, there are certain assumptions for the POSIX thread definition regarding the underlying operating system - e.g. compliancy of the underlying operating system to other parts of POSIX (which is certainly not fulfilled in case of DOS).

Only _if_ the thread library uses the underlying OS. But that is not necessary:

http://tabard.wordpress.com/2006/10/07/user-space-threads-vs-kernel-threads/

-Michael

Reply by email

Tomas Hajny
to Michael Schnell: In fact here seems to be a library that might be usable:…
Michael Schnell wrote
In fact here seems to be a library that might be usable: http://www.arl.wustl.edu/~fredk/Courses/OS/wuthreads.html

All of your links refer to Unix (or even explicitly Linux). Even just the definition of "kernel space" and "user space" gives different results for DOS and POSIX. Moreover, then end of
http://www.e-reading.mobi/chapter.php/143358/128/Tanenbaum_-_Distributed_operating_systems.html suggests that pre-emptive multithreading is hardly possible (if at all) with pure user space implementation; FPC TThread design is based on an assumption of a pre-emptive multithreading.

Tomas

Reply by email

Michael Schnell
to Tomas Hajny
Tomas Hajny wrote
suggests that pre-emptive multithreading is hardly possible (if at all) with pure user space implementation; FPC TThread design is based on an assumption of a pre-emptive multithreading.

In fat, already many years ago, I did write a preemptive multithreading library (for 68 K) that works on bare metal with no underlying OS.

So of course this is possible.

-Michael

Reply by email

Hans-Peter Diettrich
to Michael Schnell
Show quoted text 7 lines
On 09/26/2013 01:28 PM, Tomas Hajny wrote: > suggests that pre-emptive multithreading is hardly possible (if at > all) with pure user space implementation; FPC TThread design is based > on an assumption of a pre-emptive multithreading. In fat, already many years ago, I did write a preemptive multithreading library (for 68 K) that works on bare metal with no underlying OS.

Then you wrote your own kernel with threads :-)

But I doubt that your kernel can run on top of DOS :-(

DoDi

Reply by email

Sven Barth
to Michael Schnell: In fat, already many years ago, I did write a preemptive multithreading library (for 68…
Michael Schnell wrote 9 lines
On 09/26/2013 01:28 PM, Tomas Hajny wrote: > suggests that pre-emptive multithreading is hardly possible (if at > all) with pure user space implementation; FPC TThread design is based > on an assumption of a pre-emptive multithreading. In fat, already many years ago, I did write a preemptive multithreading library (for 68 K) that works on bare metal with no underlying OS. So of course this is possible.

But on "bare metal" you don't have the OS in your way and thus can of course implement preemptive multithreading as other operating systems are also able to implement preemptive multithreading...

Regards,
Sven

Reply by email

Sven Barth
to Tomas Hajny: All of your links refer to Unix (or even explicitly Linux). Even just the definition of…
Tomas Hajny wrote 12 lines
On Thu, September 26, 2013 11:55, Michael Schnell wrote: > In fact here seems to be a library that might be usable: > > http://www.arl.wustl.edu/~fredk/Courses/OS/wuthreads.html All of your links refer to Unix (or even explicitly Linux). Even just the definition of "kernel space" and "user space" gives different results for DOS and POSIX. Moreover, then end of http://www.e-reading.mobi/chapter.php/143358/128/Tanenbaum_-_Distributed_operating_systems.html suggests that pre-emptive multithreading is hardly possible (if at all) with pure user space implementation; FPC TThread design is based on an assumption of a pre-emptive multithreading.

Well, we do have a TThread.Yield procedure since the last time I worked on TThread :)

Regards,
Sven

Reply by email

Tomas Hajny
to Sven Barth: Well, we do have a TThread.Yield procedure since the last time I worked on TThread :) Sven
Sven Barth wrote 18 lines
On 26.09.2013 13:28, Tomas Hajny wrote: > On Thu, September 26, 2013 11:55, Michael Schnell wrote: >> In fact here seems to be a library that might be usable: >> >> http://www.arl.wustl.edu/~fredk/Courses/OS/wuthreads.html > > All of your links refer to Unix (or even explicitly Linux). Even just > the > definition of "kernel space" and "user space" gives different results > for > DOS and POSIX. Moreover, then end of > http://www.e-reading.mobi/chapter.php/143358/128/Tanenbaum_-_Distributed_operating_systems.html > suggests that pre-emptive multithreading is hardly possible (if at all) > with pure user space implementation; FPC TThread design is based on an > assumption of a pre-emptive multithreading. Well, we do have a TThread.Yield procedure since the last time I worked on TThread :)

Well, that is nice, but I haven't seen a statement (with an appropriately big exclamation mark ;-) ) about all started threads using this API being required to call this procedure regularly...

Tomas

Reply by email

Michael Schnell
to Sven Barth: But on "bare metal" you don't have the OS in your way and thus can of course implement…
Sven Barth wrote
But on "bare metal" you don't have the OS in your way and thus can of course implement preemptive multithreading as other operating systems are also able to implement preemptive multithreading...

How do you think DOS would "get in the way" ?

As this is Dos, only a single program runs. Same gaps the interrupts it wants to handle (e.g. timer, keyboard or serial, this in fact is a usual way to do DOS programs). Now it runs and DOS sleeps.

-Michael

Reply by email

Tomas Hajny
to Michael Schnell
Michael Schnell wrote 7 lines
On 09/26/2013 02:09 PM, Sven Barth wrote: > > But on "bare metal" you don't have the OS in your way and thus can of > course implement preemptive multithreading as other operating systems > are also able to implement preemptive multithreading... How do you think DOS would "get in the way" ?

Normally because the application using the library needs to use the operating system services (e.g. I/O functions). As long as we talk about DOS applications (and DOS RTL), this is done using DOS functions.

As this is Dos, only a single program runs. Same gaps the interrupts it wants to handle (e.g. timer, keyboard or serial, this in fact is a usual way to do DOS programs). Now it runs and DOS sleeps.

...except when it uses just any RTL function...

Tomas

Reply by email

Michael Schnell
to Tomas Hajny
Tomas Hajny wrote
...except when it uses just any RTL function..

Supposedly nearly all RTL function in DOS are not problematic as they either do simple stuff (get the current time - even this supposedly is done without a "DOS" call), do unrelated stuff (disk I/O) or in fact don't use the slow function provided by DOS or BIOS (keyboard, serial, ....)

The timer might need some dedicated handling, though.

But my knowledge on all this is far in the past, in fact based on TurboPascal.

-Michael

Reply by email

Sven Barth
to Tomas Hajny: Well, that is nice, but I haven't seen a statement (with an appropriately big exclamation…
Tomas Hajny wrote 23 lines
On Thu, September 26, 2013 14:11, Sven Barth wrote: > On 26.09.2013 13:28, Tomas Hajny wrote: >> On Thu, September 26, 2013 11:55, Michael Schnell wrote: >>> In fact here seems to be a library that might be usable: >>> >>> http://www.arl.wustl.edu/~fredk/Courses/OS/wuthreads.html >> >> All of your links refer to Unix (or even explicitly Linux). Even just >> the >> definition of "kernel space" and "user space" gives different results >> for >> DOS and POSIX. Moreover, then end of >> http://www.e-reading.mobi/chapter.php/143358/128/Tanenbaum_-_Distributed_operating_systems.html >> suggests that pre-emptive multithreading is hardly possible (if at all) >> with pure user space implementation; FPC TThread design is based on an >> assumption of a pre-emptive multithreading. > > Well, we do have a TThread.Yield procedure since the last time I worked > on TThread :) Well, that is nice, but I haven't seen a statement (with an appropriately big exclamation mark ;-) ) about all started threads using this API being required to call this procedure regularly...

I believe that we can agree that if someone wants to port an application to a system that provides only cooperative multithreading that he/she needs to ensure that his/her threads call Yield regularly. :) Afterall our main targets are preemptive ones...

Regards,
Sven

Reply by email

Tomas Hajny
to Michael Schnell: Supposedly nearly all RTL function in DOS are not problematic as they either do simple…
Michael Schnell wrote 8 lines
On 09/26/2013 02:59 PM, Tomas Hajny wrote: > ...except when it uses just any RTL function.. Supposedly nearly all RTL function in DOS are not problematic as they either do simple stuff (get the current time - even this supposedly is done without a "DOS" call), do unrelated stuff (disk I/O) or in fact don't use the slow function provided by DOS or BIOS (keyboard, serial, ....)

.
.

Actually, disk I/O is _highly_ related (as are all standard console I/O operations).

Tomas

Reply by email

Michael Schnell
to Tomas Hajny
Tomas Hajny wrote
Actually, disk I/O is _highly_ related

I don't see how it would interfere with program - internal multithreading.

(as are all standard console I/O operations).

IIRC, the TurboPascal RTL did this without using DOS or BIOS. Maybe the FPC RTL works different. Anyway, as in Lazarus GUI actions are forbidden in worker Threads this could be imposed here, too.

-Michael

Reply by email

Leif Ekblad
to Michael Schnell: My intention with this was the (original) POSIX thread definition, that (IIRC) does not…

DOS extenders are even worse candidates for multitasking than DOS. And if you aim to use 32-bit anyway, I see no reason to use an DOS extender over a real multitasking OS.

Leif

Earlier message 30 lines
----- Original Message ----- From: "Michael Schnell" To: Sent: Thursday, September 26, 2013 9:39 AM Subject: Re: [fpc-devel] Multithreading under DOS > On 09/25/2013 07:13 PM, Tomas Hajny wrote: >> Anyway, interesting thread. ;-) Still, the overall goal (or set of goals) >> is not clear for me > > My intention with this was the (original) POSIX thread definition, that > (IIRC) does not require or rely on an external OS that (besides > multitasking multiple applications) helps with implementing multithreading > within an application. > > Here the old style ("light weight" / "internal" multi-thread enabled) > pthread lib might help. Supposedly same does not need to be "installed" > but could be statically linked to. > > (But don't ask me where such a beast can be found...) > > Supposedly same only comes in 32 Bit flavor, thus a DOS extender or GO32 > will be necessary to run such programs. > > -Michael > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Leif Ekblad
to Bernd Oppolzer: I believe that DOS from its design is so limited that the only solution is what OS/2 did:…

The problem with multitasking under DOS is that the DOS int 21h call will switch stacks before doing anything useful. That means you cannot multitask DOS calls in the same virtual machine (unless you provide a fully emulated DOS environment as my RDOS OS did some 10 years ago). BIOS is less problematic, but also has static data that wasn't designed for multitasking. So you need to put a big lock on DOS and BIOS calls, and you cannot use APIs that block (because that will block everything).

Leif

Earlier message 28 lines
----- Original Message ----- From: "Bernd Oppolzer" To: "FPC developers' list" Sent: Thursday, September 26, 2013 11:40 AM Subject: Re: [fpc-devel] Multithreading under DOS > Am 26.09.2013 11:07, schrieb Tomas Hajny: >>> Here the old style ("light weight" / "internal" multi-thread enabled) >>> pthread lib might help. Supposedly same does not need to be "installed" >>> but could be statically linked to. >> You can run another operating system on top of DOS (that's basically what >> DOS extenders did), but you still need to find the solution first (and >> the >> solution is not the "POSIX threads library", but the "extender"). >> >> Tomas >> > I believe that DOS from its design is so limited that the only > solution is what OS/2 did: isolate every DOS session and > give it an own - single threaded - copy of a virtual machine, > where DOS can run the old DOS applications. > > The POSIX threads should be moved to or implemented on > "real" operating systems. > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Leif Ekblad
to Michael Schnell: How do you think DOS would "get in the way" ? As this is Dos, only a single program runs.…

It works as long as you don't try to reenter DOS (because the DOS API switches stacks).

DOS never "sleeps". DOS is invoked as you use int 21h.

Leif

Earlier message 24 lines
----- Original Message ----- From: "Michael Schnell" To: Sent: Thursday, September 26, 2013 2:45 PM Subject: Re: [fpc-devel] Multithreading under DOS > On 09/26/2013 02:09 PM, Sven Barth wrote: >> >> But on "bare metal" you don't have the OS in your way and thus can of >> course implement preemptive multithreading as other operating systems are >> also able to implement preemptive multithreading... > > How do you think DOS would "get in the way" ? > > As this is Dos, only a single program runs. Same gaps the interrupts it > wants to handle (e.g. timer, keyboard or serial, this in fact is a usual > way to do DOS programs). Now it runs and DOS sleeps. > > -Michael > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Nikolay Nikolov
to Tomas Hajny: . . In addition to the InDOS flag, DOS int 21h, AX=5D06h suggests some options for…
Tomas Hajny wrote
Anyway, interesting thread. ;-) Still, the overall goal (or set of goals) is not clear for me from the limited context included:

Ok, here's my point:

Since the FPC RTL offers pluggable thread manager support, we can offer multiple implementations. Just like Linux has cthreads, we can have several threading options.

1) One that requires DR-DOS and its multitasker. This one would be the easiest to implement for both i8086-msdos and i386-go32v2 and may be a good enough reason enough not to disable the threading support for DOS (i.e. to not treat threadvar as regular var).
2) Cooperative multithreading, which requires each thread to call .yield periodically. This can also be implemented in both i8086-msdos and i386-go32v2 and should also be easy and compatible.
3) Preemptive multitasking, implemented in the RTL. This will be the hardest one to implement, but is certainly possible at least in i8086-msdos. For i386-go32v2 I'm not so sure. As I said, I believe it would require extensions to the DPMI host. This can be done by extending cwsdpmi or some other open source DPMI host and I guess it would be hard to stabilize, but it's still quite possible. And, if done correctly, would work under regular DOS under real mode or even a VCPI host like emm386.exe, but will certainly not work under a windows dos prompt or while some other dos extender/dpmi host/multitasker is used.

Ideally, all 3 can be implemented, but any of the three would be an improvement to the current situation under DOS, which is no threading at all. And none of the 3 would be good enough to be put as the default thread manager, because each one has some drawbacks, that have to be considered carefully by the programmer, so it should be left to the programmer to choose. The drawbacks for each one are the following:

1) requirement of DR-DOS
2) the need to add calls to .yield
3) stability and compatibility issues with certain dos boxes (including the windows command prompt) and perhaps drivers

Nikolay

Reply by email

Leif Ekblad
to Nikolay Nikolov

RDOS (my OS) runs well on an 386 with 4MB, but it no longer supports emulating DOS, and the FPC adaption I did many years ago probably is broken. OTOH, it would be possible to adapt the FPC RTL to RDOS, provided it is thread-safe, and that way provide a light-weight environment. I have an RTL implementation for OpenWatcom, which right now is my primary environment. And RDOS supports modern hardware (including multicore), something DOS never will do.

Leif

Earlier message 18 lines
----- Original Message ----- From: "Nikolay Nikolov" To: Sent: Thursday, September 26, 2013 7:48 PM Subject: Re: [fpc-devel] Multithreading under DOS > On 09/26/2013 08:24 PM, Leif Ekblad wrote: >> DOS extenders are even worse candidates for multitasking than DOS. And if >> you aim to use 32-bit anyway, I see no reason to use an DOS extender over >> a real multitasking OS. > Low resource usage perhaps. How well does Linux run on a 386 with 4 MB of > RAM? What about 2 MB? :) > > Nikolay > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Sven Barth
to Nikolay Nikolov: Low resource usage perhaps. How well does Linux run on a 386 with 4 MB of RAM? What about…
Nikolay Nikolov wrote 6 lines
On 09/26/2013 08:24 PM, Leif Ekblad wrote: > DOS extenders are even worse candidates for multitasking than DOS. And > if you aim to use 32-bit anyway, I see no reason to use an DOS > extender over a real multitasking OS. Low resource usage perhaps. How well does Linux run on a 386 with 4 MB of RAM? What about 2 MB? :)

See here:
http://hackaday.com/2011/08/12/installing-linux-on-a-386-laptop/ (with 4 MB)

Please note that 386 support was completely dropped recently from the kernel:
http://www.zdnet.com/good-bye-386-linux-to-drop-support-for-i386-chips-with-next-major-release-7000008772/

Regards,
Sven

Reply by email

Sven Barth
to Hans-Peter Diettrich: What does it do on a DOS target? DoDo
Hans-Peter Diettrich wrote 6 lines
Sven Barth schrieb: > Well, we do have a TThread.Yield procedure since the last time I > worked on TThread :) What does it do on a DOS target?

Currently it will print this:

=== output begin ===

This binary has no thread support compiled in.
Recompile the application with a thread-driver in the program uses clause before other units using thread.

=== output end ===

This is the standard implementation of threading functions if no other thread manager is provided (TThread.Yield calls System.ThreadSwitch which calls TThreadManager.ThreadSwitch). Otherwise it will depend on the threading manager implemented... (see Nikolay's other mail)

Regards,
Sven

Reply by email

Nikolay Nikolov
to Sven Barth: See here: http://hackaday.com/2011/08/12/installing-linux-on-a-386-laptop/ (with 4 MB)…
Sven Barth wrote 11 lines
On 26.09.2013 19:48, Nikolay Nikolov wrote: > On 09/26/2013 08:24 PM, Leif Ekblad wrote: >> DOS extenders are even worse candidates for multitasking than DOS. And >> if you aim to use 32-bit anyway, I see no reason to use an DOS >> extender over a real multitasking OS. > Low resource usage perhaps. How well does Linux run on a 386 with 4 MB > of RAM? What about 2 MB? :) See here: http://hackaday.com/2011/08/12/installing-linux-on-a-386-laptop/ (with 4 MB)

Cool :) But DOS is still more fun :)

Please note that 386 support was completely dropped recently from the kernel: http://www.zdnet.com/good-bye-386-linux-to-drop-support-for-i386-chips-with-next-major-release-7000008772/

Yes, I know that, but I intentionally didn't mention it, because then people would point out the fact that you could use old versions, which would run just fine.

Nikolay

Reply by email

Hans-Peter Diettrich
to Nikolay Nikolov: Low resource usage perhaps. How well does Linux run on a 386 with 4 MB of RAM? What about…
Show quoted text 6 lines
On 09/26/2013 08:24 PM, Leif Ekblad wrote: > DOS extenders are even worse candidates for multitasking than DOS. And > if you aim to use 32-bit anyway, I see no reason to use an DOS > extender over a real multitasking OS. Low resource usage perhaps. How well does Linux run on a 386 with 4 MB of RAM? What about 2 MB? :)

My first notebook had 4 MB RAM, and Win3.1 and Word 1.0 worked very well on it :-)

DoDi

Reply by email

Nikolay Nikolov
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 10 lines
Nikolay Nikolov schrieb: > On 09/26/2013 08:24 PM, Leif Ekblad wrote: >> DOS extenders are even worse candidates for multitasking than DOS. >> And if you aim to use 32-bit anyway, I see no reason to use an DOS >> extender over a real multitasking OS. > Low resource usage perhaps. How well does Linux run on a 386 with 4 > MB of RAM? What about 2 MB? :) My first notebook had 4 MB RAM, and Win3.1 and Word 1.0 worked very well on it :-)

Yes, but windows 3.1 is a DOS extender :)

Nikolay

Reply by email

Travis Siegel
to Tomas Hajny: Well, there are certain assumptions for the POSIX thread definition regarding the…

Vmix was an excellent multitasker. Recently, it's been (partially) released as opensource, though it's nowhere near as complete as the old shareware product was. Vmix operated by the simple expedient of creating a virtual 8086 machine for each simultaneous program the user wished to run. It worked very well, and I'm honestly surprised it didn't get more usage than it did. Something like that would be perfect for a multitasking/multithreading dos. I believe this is the approach early versions of windows used (pre 3.0 maybe?) It obviously doesn't solve everything, but if someone were to write such a thing, and modify the underlying dos implementation to match, you could quite reasonably create a multitasking/multiuser version of dos that was probably 60-70 percent compatible with existing dos apps. It'd be a fun project, though I'm sure my assembly skills aren't up to the task.

Reply by email

Travis Siegel
to Nikolay Nikolov: Ok, here's my point: Since the FPC RTL offers pluggable thread manager support, we can…

What's preventing any threading library from launching it's own program in a virtual 8086 machine, thereby leaving dos in it's own space. Any dos calls could simply be routed to that version of already running dos. Dos supports redirection, so if it's just a matter of getting some output, problem solved.
Create virtual 8086 machines, run plain dos in one, your program in another, and simply redirect any and all dos calls to the version of dos already running in it's own 8086 machine. Sure, it'd be a bottleneck if it's bombarded with multiple requests, but dos already knows how to deal with that, so again, no problem.

Reply by email

Tomas Hajny
to Nikolay Nikolov: Yes, but windows 3.1 is a DOS extender :) Nikolay
Nikolay Nikolov wrote 8 lines
On 09/26/2013 09:41 PM, Hans-Peter Diettrich wrote: > Nikolay Nikolov schrieb: >> On 09/26/2013 08:24 PM, Leif Ekblad wrote: >>> DOS extenders are even worse candidates for multitasking than DOS. >>> And if you aim to use 32-bit anyway, I see no reason to use an DOS >>> extender over a real multitasking OS. >> Low resource usage perhaps. How well does Linux run on a 386 with 4 >> MB of RAM? What about 2 MB? :)

How much does the 386 CPU with 2 MB of appropriate RAM cost today? How much power and cooling does it need? How much reliable would be the HW compared to more up to date alternatives (let's say ARM or MIPS with 512 MB RAM and an SSD running Linux)?

Anyway, as I mentioned - I can imagine that it may be fun (similarly to my attempts to keep and improve the OS/2 support which is also used very rarely by others at best ;-) ), I just wanted to understand if there was any idea how it would be used in reality.

> My first notebook had 4 MB RAM, and Win3.1 and Word 1.0 worked very > well on it :-) Yes, but windows 3.1 is a DOS extender :)

Yes. Moreover, an extender not featuring multi-threading and even the multitasking wasn't preemptive if I remember correctly.

Tomas

Reply by email

Nikolay Nikolov
to Tomas Hajny
Tomas Hajny wrote 18 lines
On Thu, September 26, 2013 21:03, Nikolay Nikolov wrote: > On 09/26/2013 09:41 PM, Hans-Peter Diettrich wrote: >> Nikolay Nikolov schrieb: >>> On 09/26/2013 08:24 PM, Leif Ekblad wrote: >>>> DOS extenders are even worse candidates for multitasking than DOS. >>>> And if you aim to use 32-bit anyway, I see no reason to use an DOS >>>> extender over a real multitasking OS. >>> Low resource usage perhaps. How well does Linux run on a 386 with 4 >>> MB of RAM? What about 2 MB? :) How much does the 386 CPU with 2 MB of appropriate RAM cost today? How much power and cooling does it need? How much reliable would be the HW compared to more up to date alternatives (let's say ARM or MIPS with 512 MB RAM and an SSD running Linux)? Anyway, as I mentioned - I can imagine that it may be fun (similarly to my attempts to keep and improve the OS/2 support which is also used very rarely by others at best ;-) ), I just wanted to understand if there was any idea how it would be used in reality.

Well, if you go into details, there's not much use in using DOS at all, even without multithreading and multitasking. I'm using it for the fun factor mostly.

Show quoted text 5 lines
>> My first notebook had 4 MB RAM, and Win3.1 and Word 1.0 worked very >> well on it :-) > Yes, but windows 3.1 is a DOS extender :) Yes. Moreover, an extender not featuring multi-threading and even the multitasking wasn't preemptive if I remember correctly.

Actually, in 386 enhanced mode the multitasking was preemptive for DOS applications, but Win16 applications used cooperative multitasking. But Microsoft later made a DOS extender that supported full preemptive multitasking and multithreading. They called it Windows 95 :)

Nikolay

Reply by email

Unknown author
Leif Ekblad wrote
DOS extenders are even worse candidates for multitasking than DOS. And if you aim to use 32-bit anyway, I see no reason to use an DOS extender over a real multitasking OS.

does that include old systems like PC-MOS?

ok, maybe it wasn't 32bit but it was multi-user multi-tasking and ran many DOS programs without problem... we ran one of our dBaseIII/IV/Foxbase (before m$ got hold of it) accounting packages on PC-MOS and i used PC-MOS as a development environment for other similar dB/FB development... it was especially easy to watch code running on one wyse terminal while feeding data on from another terminal and debugging on the main terminal...

Reply by email

Hans-Peter Diettrich
to Nikolay Nikolov: Yes, but windows 3.1 is a DOS extender :) Nikolay
Show quoted text 12 lines
On 09/26/2013 09:41 PM, Hans-Peter Diettrich wrote: > Nikolay Nikolov schrieb: >> On 09/26/2013 08:24 PM, Leif Ekblad wrote: >>> DOS extenders are even worse candidates for multitasking than DOS. >>> And if you aim to use 32-bit anyway, I see no reason to use an DOS >>> extender over a real multitasking OS. >> Low resource usage perhaps. How well does Linux run on a 386 with 4 >> MB of RAM? What about 2 MB? :) > > My first notebook had 4 MB RAM, and Win3.1 and Word 1.0 worked very > well on it :-) Yes, but windows 3.1 is a DOS extender :)

That's why I mentioned it :-)

Such a *useful* extender can become very large, when it includes multitasking, threading, messaging etc.

DoDi

Reply by email

Hans-Peter Diettrich
to Tomas Hajny: How much does the 386 CPU with 2 MB of appropriate RAM cost today? How much power and…
Show quoted text 6 lines
>> My first notebook had 4 MB RAM, and Win3.1 and Word 1.0 worked very >> well on it :-) > Yes, but windows 3.1 is a DOS extender :) Yes. Moreover, an extender not featuring multi-threading and even the multitasking wasn't preemptive if I remember correctly.

I remember running three DOS apps on my similarly equipped desktop, in separate DOS boxes, copying files in Explorer, and playing Solitaire while waiting for another program to finish :-)

DoDi

Reply by email

Michael Schnell
to Leif Ekblad: It works as long as you don't try to reenter DOS (because the DOS API switches stacks).…
Leif Ekblad wrote
It works as long as you don't try to reenter DOS (because the DOS API switches stacks).

Yep. But there are ways to handle this. Lots of old-time Dos appliances did so (see my other post)

DOS never "sleeps". DOS is invoked as you use int 21h.

Yep. So the "DOS multithread RTL" flavor need to handle this whenever you do an int 21h.

-Michael

Reply by email

Michael Schnell
to Hans-Peter Diettrich: I remember running three DOS apps on my similarly equipped desktop, in separate DOS…
Hans-Peter Diettrich wrote 5 lines
I remember running three DOS apps on my similarly equipped desktop, in separate DOS boxes, copying files in Explorer, and playing Solitaire while waiting for another program to finish :-)

In fact I remember that there even was a "multitasking" add-on for DOS. Same allowed for switching between multiple DOS desktops without needing a graphical UI. I don't remember the features and the requirements.

-Michael

Reply by email

Michael Schnell
to Tomas Hajny: Normally because the application using the library needs to use the operating system…
Tomas Hajny wrote
...except when it uses just any RTL function...

ther were lots of "DOS appliances" that could be installed as resident add-ons. Same e.g. could handle printer queues as well for the local user as for remote network clients in the background. they could show a user interface when activated by a hotkey or some other event. So they did use disk-IO, keyboard, screen and timer hardware.

The technology used as hooking the appropriate hardware interrupts and DOS API functions and after doing their stuff calling the original (or previously installed resident appliance).

In fact I remember that at that time I had lots of those running in the background of my DOS PC.

Obviously the appropriate issues (such as non-reentant DOS calls) have been handled in a perfect way.

I am positive that this could be done by a multithreading aware DOS RTL flavor that does user-land reentrand thread scheduling according to the original (program.internal only) POSIX specs.

(But of course this is not exactly trivial. :-( )

-Michael

Reply by email

Nikolay Nikolov
to Marco van de Voort: In our previous episode, Nikolay Nikolov said: Where can I buy machines with 4MB RAM? It…
Marco van de Voort wrote 7 lines
In our previous episode, Nikolay Nikolov said: >> if you aim to use 32-bit anyway, I see no reason to use an DOS >> extender over a real multitasking OS. > Low resource usage perhaps. How well does Linux run on a 386 with 4 MB > of RAM? What about 2 MB? :) Where can I buy machines with 4MB RAM? It will be hard to find a sub 256MB machine.

Here:

http://www.ebay.com/sch/Vintage-Computing-/11189/i.html?_from=R40&_nkw=vintage+computing

Nikolay

Reply by email

Marco van de Voort
to Nikolay Nikolov

In our previous episode, Nikolay Nikolov said:

Show quoted text 7 lines
>> Low resource usage perhaps. How well does Linux run on a 386 with 4 MB >> of RAM? What about 2 MB? :) > Where can I buy machines with 4MB RAM? It will be hard to find a sub 256MB > machine. Here: http://www.ebay.com/sch/Vintage-Computing-/11189/i.html?_from=R40&_nkw=vintage+computing

I looked, and P-II,III,IV were actually more affordable :-) They can be gotten /locally/ at near zero cost. (and then I'm not even talking about them being beefier).

IOW, low resource use is not a cost issue. The only reason to want low resources is for fun, attempts to justify that desire sound a bit dodgy :-)

Reply by email

Jonas Maebe
to Marco van de Voort
Marco van de Voort wrote 10 lines
In our previous episode, Nikolay Nikolov said: >>> Low resource usage perhaps. How well does Linux run on a 386 with 4 MB >>> of RAM? What about 2 MB? :) >> Where can I buy machines with 4MB RAM? It will be hard to find a sub 256MB >> machine. > Here: > > http://www.ebay.com/sch/Vintage-Computing-/11189/i.html?_from=R40&_nkw=vintage+computing I looked, and P-II,III,IV were actually more affordable :-) They can be

[snip]

Please move this discussion to fpc-other, and limit fpc-devel to discussions in this context to the ones about actually developing a thread manager for Dos using FPC.

Thanks,

Jonas
FPC mailing lists admin

Reply by email

Tomas Hajny
to Michael Schnell: Yep. But there are ways to handle this. Lots of old-time Dos appliances did so (see my…
Michael Schnell wrote
On 09/26/2013 07:31 PM, Leif Ekblad wrote:

.
.

> DOS never "sleeps". DOS is invoked as you use int 21h. Yep. So the "DOS multithread RTL" flavor need to handle this whenever you do an int 21h.

"DOS multithread RTL" would be something very different from the original idea of a pluggable thread manager (potentially using some sort of external library as previously suggested by you) - both implementation-wise and also regarding its behaviour/limitations.

Tomas

Reply by email

Bernd Oppolzer
to Tomas Hajny: How much does the 386 CPU with 2 MB of appropriate RAM cost today? How much power and…
Tomas Hajny wrote 12 lines
How much does the 386 CPU with 2 MB of appropriate RAM cost today? How much power and cooling does it need? How much reliable would be the HW compared to more up to date alternatives (let's say ARM or MIPS with 512 MB RAM and an SSD running Linux)? Anyway, as I mentioned - I can imagine that it may be fun (similarly to my attempts to keep and improve the OS/2 support which is also used very rarely by others at best ;-) ), I just wanted to understand if there was any idea how it would be used in reality.

Only for the record:

I have two OS/2 machines running - used for developing portable C applications,
for example targetting Windows, Unix and IBM mainframes - and I would like to get
a version of FPC running there, producing executables for OS/2 and for the virtual DOS boxes inside OS/2, too - if that is possible.

But I didn't find the time to do it, so far. On Win XP, everything runs fine,
but a cross-compile there with OS/2 target didn't work. Don't know what I missed. Is it possible to build FPC on the OS/2 machines, directly? How could I do that?

You could answer me offline, if you like.

Kind regards

Bernd

Reply by email

Thaddy
to DaWorm

Even that is TSR based, not a real multi-tasker.
Under DOS a process can be swapped out and re-activated by a hardware interupt, either f.e. a timer or the keyboard.
So, at most, co-operative multi-tasking in the sense that multiple processes can run at the same time.
Because DOS is non-re entrant real multitasking will be very hard to achieve. It would be done by now ;)

DaWorm wrote 19 lines
On Sep 27, 2013 3:27 AM, "Michael Schnell" < > wrote: > > In fact I remember that there even was a "multitasking" add-on for DOS. Same allowed for switching between multiple DOS desktops without needing a graphical UI. I don't remember the features and the requirements. Perhaps you are thinking of Desqview/386? Jeff _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Michael Schnell
to Thaddy: Even that is TSR based, not a real multi-tasker. Under DOS a process can be swapped out…
Thaddy wrote 8 lines
Even that is TSR based, not a real multi-tasker. Under DOS a process can be swapped out and re-activated by a hardware interupt, either f.e. a timer or the keyboard. So, at most, co-operative multi-tasking in the sense that multiple processes can run at the same time. Because DOS is non-re entrant real multitasking will be very hard to achieve. It would be done by now ;)

You are probably right.

But those nice little DOS - Appliances (most vividly I remember one by Innominate, that in the background acted as a Novel Print server) seemingly did something very close to preemptive multitasking.

-Michael

Reply by email

Tomas Hajny
to Bernd Oppolzer: Only for the record: I have two OS/2 machines running - used for developing portable C…
Bernd Oppolzer wrote
Am 26.09.2013 22:33, schrieb Tomas Hajny:

Hi Bernd,

.
.

Show quoted text 14 lines
> Anyway, as I mentioned - I can imagine that it may be fun (similarly to > my attempts to keep and improve the OS/2 support which is also used very > rarely by others at best ;-) ), I just wanted to understand if there was > any idea how it would be used in reality. > > Only for the record: I have two OS/2 machines running - used for developing portable C applications, for example targetting Windows, Unix and IBM mainframes - and I would like to get a version of FPC running there, producing executables for OS/2 and for the virtual DOS boxes inside OS/2, too - if that is possible.

Yes, that is perfectly possible. As you probably know, native OS/2 version is available from our download pages and you may easily install the files necessary for targetting the DOS boxes in one shot (using the same installer included in the OS/2 version - just add the smaller ZIP files included in the GO32v2 version into the same directory where you also unpack the OS/2 big ZIP file and select whatever you like to include in the installer form).

The only minor issue with cross-compiling from OS/2 to GO32v2 using the 2.6.x version is that you still need an external linker for that and this makes things a bit more difficult (mostly due to the way how invocation of DOS programs from OS/2 sessions works and potentially also due to OS/2 VDMs not providing LFN support which may be necessary when working with long file names - including those found in some FPC packages). This issue doesn't exist with the trunk version any longer since internal GO32v2 linker is included there.

Show quoted text 7 lines
But I didn't find the time to do it, so far. On Win XP, everything runs fine, but a cross-compile there with OS/2 target didn't work. Don't know what I missed. Is it possible to build FPC on the OS/2 machines, directly? How could I do that? You could answer me offline, if you like.

Actually, I already answered to your question in July in thread "Porting FPC to IBM zArch" - see
http://lists.freepascal.org/lists/fpc-devel/2013-July/032499.html (I suppose that it dropped your attention somehow). My offer from bottom of that e-mail is still valid, of course - if you have issues, let me know (either via fpc-pascal list or directly).

Tomas

Reply by email

Kostas Michalopoulos
to Marco van de Voort: In our previous episode, Nikolay Nikolov said: Where can I buy machines with 4MB RAM? It…

I suppose something like this:
http://www.commell-sys.com/Product/SBC/LE-330.htm ? Also i see some 64MB devices on other sites, although those run Linux fine.

Marco van de Voort wrote 12 lines
In our previous episode, Nikolay Nikolov said: > > if you aim to use 32-bit anyway, I see no reason to use an DOS > > extender over a real multitasking OS. > Low resource usage perhaps. How well does Linux run on a 386 with 4 MB > of RAM? What about 2 MB? :) Where can I buy machines with 4MB RAM? It will be hard to find a sub 256MB machine. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email