Thread-safe get (accessor method)
Posted
by sonofdelphi
on Stack Overflow
See other posts from Stack Overflow
or by sonofdelphi
Published on 2010-05-17T05:41:16Z
Indexed on
2010/05/17
5:50 UTC
Read the original article
Hit count: 138
I'm currently using the following code for thread-safe access of a variable.
int gnVariable;
void getVariableValue(int *pnValue)
{
acquireLock(); //Acquires the protection mechanism
*pnValue = gnVariable;
releaseLock(); //Releasing the protection mechanism
}
I would like to change my API signature to a more user-friendly
int getVariableValue(void);
How should I rewrite the function - such that the users of the API don't have to bother about the locking/unlocking details?
© Stack Overflow or respective owner