分类:
2009-11-19 09:55:16
CSemaphore(
LONG lInitialCount = 1,
LONG lMaxCount = 1,
LPCTSTR pstrName = NULL,
LPSECURITY_ATTRIBUTES lpsaAttributes = NULL
);
The initial usage count for the semaphore. Must be greater than or equal to 0, and less than or equal to lMaxCount .
The maximum usage count for the semaphore. Must be greater than 0.
The name of the semaphore. Must be supplied if the semaphore will be accessed across process boundaries. If NULL, the object will be unnamed. If the name matches an existing semaphore, the constructor builds a new CSemaphore object which references the semaphore of that name. If the name matches an existing synchronization object that is not a semaphore, the construction will fail.
Security attributes for the semaphore object. For a full description of this structure, see in the Platform SDK .
---------------------------------------------------
1 CSemaphore 信号量的用法,可以看上面链接msdn的例子,说的比较清楚
2 CSemaphore的初始化有个疑问。lInitialCount 可以看做资源的数目,也就是可用信号的数目。lMaxCount 是信号量的最大使用数目。lInitialCount 应该小于lMaxCount ,从逻辑上时可以理解的。但是有个问题,既然lInitialCount 已经制定了初始的信号个数,为什么还要加上个lMaxCount ?很明显lMaxCount 必须大于lInitialCount 。