lock.b 277 B

1234567891011121314151617181920212223242526
  1. implement Lock;
  2. include "sys.m";
  3. sys: Sys;
  4. include "lock.m";
  5. Semaphore.obtain(l: self ref Semaphore)
  6. {
  7. l.c <-= 0;
  8. }
  9. Semaphore.release(l: self ref Semaphore)
  10. {
  11. <-l.c;
  12. }
  13. Semaphore.new(): ref Semaphore
  14. {
  15. l := ref Semaphore;
  16. l.c = chan[1] of int;
  17. return l;
  18. }
  19. init()
  20. {
  21. }