home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / programm / 3334 < prev    next >
Encoding:
Text File  |  1992-12-21  |  2.1 KB  |  52 lines

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