Date: Mon, 19 Jun 2000 17:38:34 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: djgpp AT delorie DOT com Subject: Re: multitasking/threading in DJGPP In-Reply-To: <11c302c2.dc5124a1@usw-ex0102-084.remarq.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Sun, 18 Jun 2000, batchex wrote: > I'm thinking about allocating some memory for stack every time a > thread is registered, and change SS:ESP to the address of the > allocated stack for the current thread in every task/thread switch > (by means of timer interrupt). Bad idea: the DPMI spec explicitly forbids switching stacks inside a hardware interrupt handler. Your program will crash. Instead, I suggest to do the task switch from a signal handler for SIGALRM. You can use the `setitimer' library function to get periodic SIGALRM. The disadvantage of this method is that threading stops when one of the threads calls DOS or BIOS, until the DOS/BIOS call returns. However, by and large, this is the only way of multitasking in the DPMI environment that doesn't violate the DPMI spec. > Of course all the registers will be preserved during the task/thread > switch. Use setjmp/longjmp, and you can preserve and restore registers with minimal fuss. > How much memory must I allocate per stacks just to be save? There's no single answer to that question. DJGPP programs get 512KB of stack by default, and that is enough for most programs, so if you want to be safe, use 512KB per thread. > Any help, suggestion and ideas as well to URLs to > multitasking/threading tuts in C are greatly appreciated. Some multitasking packages are mentioned in section 22.4 of the DJGPP FAQ list.