《操作系统》的实验代码。
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

26 Zeilen
454 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. jne .acquire # if not, try again
  10. # critical section
  11. mov count, %ax # get the value at the address
  12. add $1, %ax # increment it
  13. mov %ax, count # store it back
  14. # release lock
  15. mov $0, mutex
  16. # see if we're still looping
  17. sub $1, %bx
  18. test $0, %bx
  19. jgt .top
  20. halt