我正在使用下面的代码进行线程安全访问变量。线程安全get(访问器方法)
int gnVariable;
void getVariableValue(int *pnValue)
{
acquireLock(); //Acquires the protection mechanism
*pnValue = gnVariable;
releaseLock(); //Releasing the protection mechanism
}
我想我API的签名更改为更方便用户
int getVariableValue(void);
我应该如何重写功能 - 使得API的用户不必理会锁定/解锁细节?
我不明白你的问题。您建议的API都不提供锁定细节。 – zvrba 2010-05-17 06:24:21
如果更改为第二个版本 - int getVariable(void) - ,API的用户将不得不手动释放/解锁信号量。如果你不这样做Samuel和Naveen建议 – sonofdelphi 2010-05-17 07:51:01