Open junlon2006 opened 4 years ago
尽量不要使用递归锁 1、能用递归锁的多线程互斥往往可以简化,可以优化为非递归,递归锁逻辑晦涩。 2、递归锁比非递归的性能低一些。 3、递归锁虽然允许同一个线程多次获取同一个互斥量,可重复获取的最大次数并未具体说明,一旦超过一定次数,再次lock会抛出std::system异常。
对于无限递归的测试,在macOs下测试出最大值是65536
static void __get_mutex() { int count = 0; std::recursive_mutex mutex; while (1) { cout<<count++<<endl; mutex.lock(); } }
尽量不要使用递归锁 1、能用递归锁的多线程互斥往往可以简化,可以优化为非递归,递归锁逻辑晦涩。 2、递归锁比非递归的性能低一些。 3、递归锁虽然允许同一个线程多次获取同一个互斥量,可重复获取的最大次数并未具体说明,一旦超过一定次数,再次lock会抛出std::system异常。