home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / Blitz / version-1-0 / OSProject / p3 / Synch.h < prev    next >
Text File  |  2006-04-17  |  1KB  |  54 lines

  1. header Synch
  2.  
  3.   uses Thread
  4.  
  5.   class Semaphore
  6.     superclass Object
  7.     fields
  8.       count: int
  9.       waitingThreads: List [Thread]
  10.     methods
  11.       Init (initialCount: int)
  12.       Wait ()
  13.       Signal ()
  14.   endClass
  15.  
  16.   class Mutex
  17.     superclass Object
  18.     fields
  19.       heldBy: ptr to Thread           -- Null means this mutex is unlocked.
  20.       waitingThreads: List [Thread]
  21.     methods
  22.       Init ()
  23.       Lock ()
  24.       Unlock ()
  25.       IsHeldByCurrentThread () returns bool
  26.   endClass
  27.  
  28.   class Mutex2
  29.     -- A second, equivalent implementation using Semaphores, which
  30.     -- was not included in initial version of Sync.h.
  31.     superclass Object
  32.     fields
  33.       sem: Semaphore
  34.       heldBy: ptr to Thread           -- Null means this mutex is unlocked.
  35.     methods
  36.       Init ()
  37.       Lock ()
  38.       Unlock ()
  39.       IsHeldByCurrentThread () returns bool
  40.   endClass
  41.  
  42.   class Condition
  43.     superclass Object
  44.     fields
  45.       waitingThreads: List [Thread]
  46.     methods
  47.       Init ()
  48.       Wait (mutex: ptr to Mutex)
  49.       Signal (mutex: ptr to Mutex)
  50.       Broadcast (mutex: ptr to Mutex)
  51.   endClass
  52.  
  53. endHeader
  54.