home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!haven.umd.edu!news.umbc.edu!umbc8.umbc.edu!reagle
- From: reagle@umbc8.umbc.edu (Mr. Joseph Reagle; MEYERHOFF (U))
- Subject: Re: Semaphores, Swap, or Test_And_Set
- Message-ID: <1992Dec18.195139.15322@umbc3.umbc.edu>
- Sender: newspost@umbc3.umbc.edu (News posting account)
- Organization: University of Maryland, Baltimore County Campus
- References: <1992Dec18.045022.15255@umbc3.umbc.edu> <1gsscvINNa2r@usenet.INS.CWRU.Edu>
- Date: Fri, 18 Dec 1992 19:51:39 GMT
- Lines: 40
-
- In article <1gsscvINNa2r@usenet.INS.CWRU.Edu> trier@slc6.ins.cwru.edu (Stephen C. Trier) writes:
- >Well, most systems end up implementing them in one way or another.
- >Here's a simplistic way to do it, in pseudocode:
- >
- > Mask all interrupts
- > Do the atomic instruction
- > Unmask interrupts
- >
- >This approach is actually quite common in MS-DOS. I have seen it all
- >over the place in MS-DOS network software. The ensuing lost interrupts
- >are nothing to sneeze at, though. Interrupt masking should never be
- >done when not absolutely necessary.
-
- Sounds like a pain, I'm not familiar with how DOS deals with
- deals with interupts whether priority based, FCFS, interupts could
- occur but only queued and not actually do anything if a process has
- requested this-keeping atomicity while not loosing interupts.
-
-
- >The 8086 family, however, supports a number of atomic operations. XCHG
- >is atomic. Any other test-and-set instruction, like INC, DEC, and many
- >others, can be made atomic through use of the LOCK prefix.
-
- Don't know what xchg does and I am not quite sure how to
- implement test_and_set using inc or dec.
-
- Are you refering to a bit TS and use DEC to decrement the PC until
- false?
- if (bit == 0) bit = 1 and PC += 2; (or return, or whatever)
- if (bit == 1) PC--;
-
- >Upon a suggestion from the net, I used INC and DEC to implement semaphores
- >in CWRU's MS-DOS network kernel. It took me all of 4 lines of assembly to
- >implement simple non-blocking versions of the P and V primitives, 20 lines
- >of assembly if they were callable from C.
-
- Would you mind passing on the C callabled assembly?
-
- Thanks for the info, it was interesting.
- Joe
-