《操作系统》的实验代码。
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

29 righe
510 B

  1. .var mutex
  2. .var count
  3. .main
  4. .top
  5. .acquire
  6. mov $1, %ax
  7. xchg %ax, mutex # atomic swap of 1 and mutex
  8. test $0, %ax # if we get 0 back: lock is free!
  9. je .acquire_done
  10. yield # if not, yield and try again
  11. j .acquire
  12. .acquire_done
  13. # critical section
  14. mov count, %ax # get the value at the address
  15. add $1, %ax # increment it
  16. mov %ax, count # store it back
  17. # release lock
  18. mov $0, mutex
  19. # see if we're still looping
  20. sub $1, %bx
  21. test $0, %bx
  22. jgt .top
  23. halt