+ -
当前位置:首页 → 问答吧 → linux 2.4.18 为什么读写信号量(rw_semaphore)最多支持32766个等待进程?

linux 2.4.18 为什么读写信号量(rw_semaphore)最多支持32766个等待进程?

时间:2010-12-10

来源:互联网

本帖最后由 铁蛋小灯泡 于 2010-12-10 14:31 编辑

/* The value of WAITING_BIAS supports up to 32766 waiting processes. This can
* be extended to 65534 by manually checking the whole MSW rather than relying
* on the S flag.
*/
  1. struct rw_semaphore {
  2.         signed long                count;
  3. #define RWSEM_UNLOCKED_VALUE                0x00000000
  4. #define RWSEM_ACTIVE_BIAS                0x00000001
  5. #define RWSEM_ACTIVE_MASK                0x0000ffff
  6. #define RWSEM_WAITING_BIAS                (-0x00010000)
  7. #define RWSEM_ACTIVE_READ_BIAS                RWSEM_ACTIVE_BIAS
  8. #define RWSEM_ACTIVE_WRITE_BIAS                (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
  9.         spinlock_t                wait_lock;
  10.         struct list_head        wait_list;
  11. #if RWSEM_DEBUG
  12.         int                        debug;
  13. #endif
  14. };
复制代码
上面的注释说: WAITING_BIAS最多可支持32766个等待者。

可是我觉得应该是32767个啊。(考虑一种场景,首先有一个写者进程,然后来了32767个读者进程在等待)
                                MSW (最高有效字,即count的高16位)
第一个等待者------       -2
第二个等待着------       -3
第32767个等待者--     -32768

作者: 铁蛋小灯泡   发布时间: 2010-12-10

考虑实际情况,PID是有个数限制的。而且,内核对进程数也有限制,我记得是32000。

作者: liuyangxky   发布时间: 2010-12-10