From: Andrew Crabtree Message-Id: <199705091617.AA062464640@typhoon.rose.hp.com> Subject: Re: Some questions about LWP. To: bigal2000 AT hotmail DOT com (Alex Holden) Date: Fri, 09 May 1997 9:17:20 PDT Cc: djgpp AT delorie DOT com In-Reply-To: <199705091000.DAA11691@f39.hotmail.com>; from "Alex Holden" at May 09, 97 3:00 am Precedence: bulk > 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)? Win 3.1 is cooperative. In order for a switch to occur, you must call an OS function (typically one to get a message from a message queue, or an explicit wait call), a switch can then occur. In pre-emptive, switches are based on timer interrupts, so they occur at regular intervals. > 5. What are re-entrant and non re-entrant, and how is it possible to ensure my > functions are re-entrant? Typically, if you use global variables your code is non-reentrant. Why? Say your procedure is called and you set the value of a global variable, now you are interrupted and reentered. The global variable gets set to a new value. When you go back to your original call the wrong value is in the global. There are two ways around this. 1) Don't use globals, don't call anything that in non-reentrant (libc stuff) 2) Semaphore procedures that are non-reentrant. You can do a busy wait, or release your time back to the OS on failure. I can send you example assembly code for both if you'd like ( very simple, just look up 'bit test and set' bts and 'bit test and reset', and follow with a jump if carry. I assume this is what the wrapped printf functions from lwp do, but I haven't checked > 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? This is trivial to do yourself, just use ar to crate a liblwp.a ar -cvr liblwp.a lwp.o lwpasm.o (the ar flags may not be correct) > 7. Are there any plans to convert libc.a to re-entrant code, so that the > modified header files are not needed? Not unless your doing it :) Andrew