读写锁,为什么要用读写锁;

时间:2025-04-06 07:50:52
  • 运行结果
  • 2 写操作开始 : 2
  • 2 写操作结束: 2
  • 1 写操作开始 : 1
  • 1 写操作结束: 1
  • 3 写操作开始 : 3
  • 3 写操作结束: 3
  • 4 写操作开始 : 4
  • 4 写操作结束: 4
  • 5 写操作开始 : 5
  • 5 写操作结束: 5
  • Thread-0 读操作开始 : 1
  • Thread-2 读操作开始 : 3
  • Thread-4 读操作开始 : 5
  • Thread-3 读操作开始 : 4
  • Thread-1 读操作开始 : 2
  • Thread-5 读操作开始 : 6
  • Thread-6 读操作开始 : 7
  • Thread-7 读操作开始 : 8
  • Thread-8 读操作开始 : 9
  • Thread-10 读操作开始 : 11
  • Thread-9 读操作开始 : 10
  • Thread-11 读操作开始 : 12
  • Thread-12 读操作开始 : 13
  • Thread-13 读操作开始 : 14
  • Thread-14 读操作开始 : 15
  • Thread-15 读操作开始 : 16
  • Thread-16 读操作开始 : 17
  • Thread-17 读操作开始 : 18
  • Thread-18 读操作开始 : 19
  • Thread-19 读操作开始 : 20
  • Thread-0 读操作结束key : 1resutl: 1
  • Thread-17 读操作结束key : 18resutl: null
  • Thread-13 读操作结束key : 14resutl: null
  • Thread-2 读操作结束key : 3resutl: 3
  • Thread-16 读操作结束key : 17resutl: null
  • Thread-9 读操作结束key : 10resutl: null
  • Thread-19 读操作结束key : 20resutl: null
  • Thread-18 读操作结束key : 19resutl: null
  • Thread-15 读操作结束key : 16resutl: null
  • Thread-14 读操作结束key : 15resutl: null
  • Thread-4 读操作结束key : 5resutl: 5
  • Thread-5 读操作结束key : 6resutl: null
  • Thread-6 读操作结束key : 7resutl: null
  • Thread-10 读操作结束key : 11resutl: null
  • Thread-11 读操作结束key : 12resutl: null
  • Thread-3 读操作结束key : 4resutl: 4
  • Thread-1 读操作结束key : 2resutl: 2
  • Thread-12 读操作结束key : 13resutl: null
  • Thread-7 读操作结束key : 8resutl: null
  • Thread-8 读操作结束key : 9resutl: null