delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/13/07:17:43

From: Jim Schwarz x3-2961 <schwarz AT sunny DOT orl DOT lmco DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Some questions about LWP.
Date: Sat, 10 May 1997 15:04:50 -0400
Organization: Lockheed Martin - Information Systems
Lines: 105
Message-ID: <3374C6D2.F2F@escmail.orl.mmc.com>
References: <199705091000 DOT DAA11691 AT f39 DOT hotmail DOT com>
NNTP-Posting-Host: marino.orl.mmc.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi,
 
 While I haven't tried LWP yet, only downloaded it, I cannot answer
specific questions about the lib. However I can answer some of your more
generic questions, here goes.
Alex Holden wrote:
> 
> I have downloaded LWP (the pre-emptive multitasking library for DJGPP), and
> wrote a couple of simple example programs with it to try it out. It seems a very
> interesting library, but I have a few questions:
> 1. What exactly is the difference between pre-emptive and co-operative
> multitasking, and why is pre-emptive described as being kuhl whilst co-operative
> is bleh (in the documentation)?

In co-operative multitasking, Once a process is given the processor and
permission to run, it has to "let go" of the processor before anyone
else can get it. This means that a misbehaved (ie non- cooperative)
process could keep the processor forever, and no other processes could
run. In pre-emptive multi-tasking, processes are run based on priority
and all tasks of equal priority will get an equal time-slice. The O/S
will interupt a task if it hasn't given up the processor, so that other
processors can get time. Note the lower priority tasks cannot get time
until all higher priority tasks are in a wait state.  The fact that
co-operative multitasking can be mis-used, and tasks can hog the
processor, is why LWP says bleh to it. It is also why Win3.1 is not a
multiuser O/S. WinNT, UNIX/Linux and O/S2 are all multiuser O/S's and
user some form of pre-emtive multitasking.

> 2. Is there a way to allocate different priorities to certain tasks so that
> functions which need a lot of processor time get a higher priority than
> functions which don't need much? Is this where co-operative multitasking comes
> in?

This is what priorities are all about. The highest priority task gets
the processor whenever it is ready to run, and the O/S has decided it's
time for another task. One note, if a task is the only process with a
particular priority, and that priority is the highest in the system, the
process can hog the CPU and never give it up.

In case your interested, giving up the processor usually means the
process perform a function that it will not or cannot complete, and it
has to wait. Sleep is one obvious way a process gives up the processor,
others are waiting for I/O from keyboard or other devices, waiting on
mailboxes or semaphores in a real-time O/S etc.

> 3. Is it possible to 'nest' tasks, so that, for example, you could spawn
> sub-procedures from tasks, or would they still all get equal priority.

I don't know about LWP, but in many systems, a spawned task has the same
priority as the parent unless it changes it priority when it runs.

> 4. As it is not possible to pass values to, or recieve values from, task
> procedures in the normal way, what is the 'usual' way of passing data to and
> from them? ie. do you have to use lots of global variables, or is there a
> 'better' way.

I don't know about LWP, but global variables are one way. Others,
usually titled message-passing functions are mailboxes and semaphores.
Global variables are the easiest to use. But can cause problems when
trying to track down problems. (This is sometimes a major topic of
discussion in S/W circles, especially with ADA programmers. Many folks
think you shouldn't use global variables, that all data should be passed
by call... Oh well getting off the subject :-).

> 5. What are re-entrant and non re-entrant, and how is it possible to ensure my
> functions are re-entrant?

When a function is re-entrant it means it can call itself, without
hosing up. You need to watch how you use the stack, and how you
initialize yourself. You need to make sure the code doesn't get lost
after multiple calls.

> 6. Are there any plans to convert LWP into a normal library (like libc.a and
> liballeg.a) or do I always have to link lwp.o and lwpasm.o in with my programs?

Not likely, unless it becomes an ANSI standard. This is pretty general
anyway, you will find all libraries you might use need special libraries
to link to. 

> 7. Are there any plans to convert libc.a to re-entrant code, so that the
> modified header files are not needed?

Again, not likely, unless it becomes a standard.

> I apologise if this is a long list of questions, but the LWP documentation is
> not very comprehensive as of yet. Thanks in advance for your help.
> |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
> |    Alex Holden- Electronics student, computer    |
> |     programmer, caver, and Land Rover nut!       |
> | http://www.geocities.com/CapeCanaveral/Lab/1532/ |
> |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
> 
> ---------------------------------------------------------
> Get Your *Web-Based* Free Email at http://www.hotmail.com
> ---------------------------------------------------------
Well, hope this all helps. If I raised more questions than answered,
feel free to drop me an email.
Jim
-- 
James E. Schwarz, Jr. PE

Staff Systems Engineer - Armor Programs
Lockheed Martin Corporation          Information Systems 
12506 Lk Underhill Rd. MP 823        Orlando, Fla 32825          
<schwarz AT escmail DOT orl DOT mmc DOT com>        Voice: (407)306-2961

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019