ReaderWriterLock vs lock{}

后端 未结 7 2181
死守一世寂寞
死守一世寂寞 2020-11-30 21:38

Please explain what are the main differences and when should I use what.
The focus on web multi-threaded applications.

7条回答
  •  旧时难觅i
    2020-11-30 22:29

    ReaderWriterLock/Slim is specifically designed to help you efficiently lock in a multiple consumer/ single producer scenario. Doing so with the lock statement is possible, but not efficient. RWL/S gets the upper hand by being able to aggressively spinlock to acquire the lock. That also helps you avoid lock convoys, a problem with the lock statement where a thread relinquishes its thread quantum when it cannot acquire the lock, making it fall behind because it won't be rescheduled for a while.

提交回复
热议问题