Date: Wed, 17 Mar 1999 11:35:00 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: djgpp AT delorie DOT com Subject: Re: Keyboard Handler question In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Tue, 16 Mar 1999, Thibaut Murez wrote: > static void SB_interrupt_handler() > { > > code > ... > read_chunk(); /* <------------- In this function I call fread*/ > ... > } > > > My question: if I lock the read_chunk function, is this code safe? > Does it locks automatically the "fread" in the read_chunk function? You should *never* call DOS inside a hardware interrupt handler. If the interrupt happens in the middle of another DOS call, your code will reenter DOS and wedge the machine, since DOS is not reentrant. In addition, library functions are not locked, unless you set the `_CRT0_FLAG_LOCK_MEMORY' bit in `_crt0_startup_flags'. So calling library functions is also a bad idea. Btw, if you run that code under CWSDPMI, it will crash your program, as section 18.11 of the FAQ explains. The best way to avoid such problems is to have the interrupt handler set a flag, so that the foreground part of your program could check that flag and read the data from file.