DOS mutex
From
Jcurtis@VERT to
ALL on Wed Jun 4 10:58:42 2025
I have a shared list. User code adds to it, interrupt code drains it.
The user update sequence must be atomic, so the list can't be corrupted
by interrupt code. Typical method is a cli/sti critical section around
the user update sequence.
But I avoid disabling interrupts when possible, and x86 xchg does the
trick. Indirect addresssing using [bx] was the only way I could make it
work. If anyone has a better trick, please advise.
--- code works with Borland C++ 3.1 ---
int data [] = {3,14,29,33,0,0,0,0,0}; /* list count in element [0] */
int *w = data; /* do not disturb when [0] == 0 */
void
main ()
{
_DX = 0; /* list count == 0 means mutex */
asm mov bx, w; /* get list count and set mutex */
asm xchg dx, [bx]; /* with CPU interrupts inhibited */
w[++_DX] = 55; /* add a new element to the list */
asm mov bx, w; /* bx got trashed, load it again */
asm xchg dx, [bx]; /* updates count and clears mutex */
_AX = 0; /* stopping place for debugger */
}
* SLMR 2.1a *
---
■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net