Mail Archives: djgpp/1999/03/17/06:53:58
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.
- Raw text -