Crazed idea for a project. (0.0.1 is here -check out)

DOS specific questions.
VonGodric
Posts: 997
Joined: May 27, 2005 9:06
Location: London
Contact:

Crazed idea for a project. (0.0.1 is here -check out)

Postby VonGodric » Mar 11, 2006 18:02

Another wave of insanity has hit me and now i'm overly excited about an idea what I'm seriously considering to turn into a project.

A DOS "shell" written in FB. Here's my idea:
Multitasking shell/kernel written in FB that can run and execute real exe's (compiled by FB). So sort of an OS that is based on DOS. Is anyone else interested in such thing?
Last edited by VonGodric on Mar 12, 2006 19:34, edited 1 time in total.
hippy
Posts: 84
Joined: Nov 04, 2005 18:13
Location: UK

Postby hippy » Mar 11, 2006 18:55

Sounds good to me. I assume there will be some inter-application communications mechanism ?

I have an MS-DOS based TCP/IP server and everytime I want to add another server or access via Serial Port ( ie SLIP / PPP etc ) etc it means altering one horrendously monolithic program ( MS-DOS PowerBasic ). Being able to just write another simple FB App to do the job and have it hook into an internal TCP/IP stack would be superb.

Or I could / should use Linux :-)
VonGodric
Posts: 997
Joined: May 27, 2005 9:06
Location: London
Contact:

Postby VonGodric » Mar 11, 2006 19:28

Anyway believe it or not I got a threading library to work on dos version. I think DrV and V1ct0r could implement my library into official FB dos version to support threads natively

Although this library is somewhat still buggy and sometimes needs to call a yealding function to pass to a next thread
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Postby v1ctor » Mar 11, 2006 19:44

The pthreads DOS port? If it runs for more than 10 secs without crashing, sure :).

I never tested it, or tried to get it to build, i think DrV tried to build it once, no idea.

It would probably fix the DOS port of the gfxlib, and allow timers (with a 55ms resolution though) and other goodies.
VonGodric
Posts: 997
Joined: May 27, 2005 9:06
Location: London
Contact:

Postby VonGodric » Mar 11, 2006 20:15

not pthreads -another small lightweight threads library. But it provides all the basics, threads, semaphores, conditions, thread priorities, and some more neat features. I think this should be sufficent to create a simple dos shell :P

Can someone test this on real dos machine? http://fbide.freebasic.net/File/fbthread.exe Works fine on my winxp box. Here's the src of this program

Code: Select all

option explicit
#include "pdmlwp.bi"

dim shared print_limit as lwp_semaphore

sub threadTest1 ( byval usrData as any ptr )
    do
        lwp_wait_semaphore(@print_limit)
            print "a";
        lwp_release_semaphore(@print_limit)
    loop
end sub

sub threadTest2 ( byval usrData as any ptr )
    do
        lwp_wait_semaphore(@print_limit)
            print "b";
        lwp_release_semaphore(@print_limit)
    loop
end sub

sub threadTest3 ( byval usrData as any ptr )
    do
        lwp_wait_semaphore(@print_limit)
            print "c";
        lwp_release_semaphore(@print_limit)
    loop
end sub

sub threadTest4 ( byval usrData as any ptr )
    do
        lwp_wait_semaphore(@print_limit)
            print "d";
        lwp_release_semaphore(@print_limit)
    loop
end sub
   
    dim thread1 as integer
    dim thread2 as integer
    dim thread3 as integer
    dim thread4 as integer
       
    if (lwp_init(0, 1024)) then
        lwp_init_semaphore (@print_limit)       
        thread1 = lwp_spawn(@threadTest1, NULL, 4096, 1)
        thread2 = lwp_spawn(@threadTest2, NULL, 4096, 1)
        thread3 = lwp_spawn(@threadTest3, NULL, 4096, 1)
        thread4 = lwp_spawn(@threadTest4, NULL, 4096, 1)
       
        while inkey$=""

        wend
       
        lwp_kill( thread1 )
        lwp_kill( thread2 )
        lwp_kill( thread3 )
        lwp_kill( thread4 )
       
    end if
MystikShadows
Posts: 612
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

Postby MystikShadows » Mar 11, 2006 21:38

I'm interested by this too, a lot :-). great idea for a project

I don't have a DOS machine to test this on, but it worked here on XP Pro and XP Home.

I'll definitaly see where this goes, in a few weeks, I may have a native DOS machine then too....looking into it....then I could perform more tests when needed...i'd like to help too :-)..

Now who here didn't think I'd be interested?? Shame on you LOL...
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Postby DrV » Mar 12, 2006 1:29

Works fine on Windows 95 here (at home for spring break, stuck with an old Pentium II :) - very cool.

If you point me at the threading lib you used, I will work on adding it to the DOS port.
D.J.Peters
Posts: 8210
Joined: May 28, 2005 3:28
Contact:

Postby D.J.Peters » Mar 12, 2006 2:52

do you mean this ?
Pre-emptive multithreading library 2.0
ftp://ftp.delorie.com/pub/djgpp/current/v2tk/jtlwp20s.zip

Extended version of LWP library
ftp://ftp.delorie.com/pub/djgpp/current/v2tk/pdmlwp03.zip
VonGodric
Posts: 997
Joined: May 27, 2005 9:06
Location: London
Contact:

Postby VonGodric » Mar 12, 2006 7:59

DRV I'll work on it a bit and then post the src and library for you to use. Links what D.J.Peters gave are right but it needs some hacking to compile and work properly on FB
VonGodric
Posts: 997
Joined: May 27, 2005 9:06
Location: London
Contact:

Postby VonGodric » Mar 12, 2006 19:36

Hey guys. First proof of concept is here:

http://fbide.freebasic.net/File/fbos001.rar

It runs two files in a "multitask" mode. very simple, but it works:P

Code: Select all

declare function fbos_Print alias "fbos_Print" ( strMessage as string )

function fbos_main alias "fbos_main" (  ) as integer
    do
        fbos_Print("b")
    loop
end function
is the code of the programs. one prints "a" and other "b"
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Postby 1000101 » Mar 12, 2006 19:45

How are you handling threading priorities, sleeping, double-locks, etc?
VonGodric
Posts: 997
Joined: May 27, 2005 9:06
Location: London
Contact:

Postby VonGodric » Mar 12, 2006 20:23

the higher is priority of the thread the more timeslices it get's.
Sleeping is done via not entering a thread at all for a given time -so there's almost no overhead because of it and on the contrary -if one thread is sleeping others get more time slices. double-locks? I van lock threading if it's needed and run in "single thread mode" until I don't need it anymore.
tunginobi
Posts: 655
Joined: Jan 10, 2006 0:44
Contact:

Postby tunginobi » Mar 13, 2006 0:39

But what about deadlocks? Say there are two threads, A and B, and two resources, X and Y. Thread A locks X for exclusive access. At the same time, thread B locks Y for exclusive access. What happens when thread A needs Y, which has been locked, while still having locked X? Thread A needs B to release its lock on Y, but B can only continue after A has released its lock on X.

Deadlock. Any way around it?
VonGodric
Posts: 997
Joined: May 27, 2005 9:06
Location: London
Contact:

Postby VonGodric » Mar 13, 2006 8:41

yes I can see the problem. For a time being these situations must be avoided until I figure out how to solve it.

It is possible to check if the resource is locked and based on the result do appropriate action (sleep some milliseconds and try again? and if fails again fire an error or try to handle differently.) usually kernel must be able to run programs and if this kind of situation happens in the client program -then I can't do much about it.
anarky
Posts: 80
Joined: Jun 02, 2005 14:54
Location: Australia
Contact:

Postby anarky » Mar 13, 2006 13:25

Build a check into the thread library which will trap this and in return, create a fake resource Y and tell the thread to use it then.

I'm in. I'd like to make a FB-based console.

EDIT: Tested on real dos machine, got error: "Load error: no DPMI - Get csdpmi*b.zip"

>anarky

Return to “DOS”

Who is online

Users browsing this forum: No registered users and 3 guests