87

读写锁的性能一定更好吗 | 一根笨茄子

 6 years ago
source link: http://blog.guoyb.com/2018/02/11/rwlock/?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
最近在写代码的时候,处理多线程间数据同步时,用到了读写锁rwlock。在多线程同步中,更常用到的是互斥量mutex,那rwlock和mutex有什么不同和优劣呢? 首先,一个常见的误区是,认为在读多写少的情况下,rwlock的性能一定要比mutex高。实际上,rwlock由于区分读锁和写锁,每次加锁时都要做额外的逻辑处理(如区分读锁和写锁、避免写锁“饥饿”等等),单纯从性能上来讲是要低于更为

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK