ambuli
asked on
handling pthread_mutex_lock, pthread_mutex_unlock errors
Hi Experts,
Assuming I have the following code for creating a singleton, how can I handle if error is returned from pthread functions? What is a good way to handle it.
If I have a setter function like below, what could be the better way to handle pthread errors.
Assuming I have the following code for creating a singleton, how can I handle if error is returned from pthread functions? What is a good way to handle it.
Manager * Manager::getInstance()
{
if (_instance == 0)
{
pthread_mutex_lock(&_instanceMutex);
if (_instance == 0) // double checked
{
_instance = new Manager();
}
pthread_mutex_unlock(&_instanceMutex);
}
return _instance;
}
If I have a setter function like below, what could be the better way to handle pthread errors.
void DataHolder::setSomething(int data)
{
pthread_mutex_lock(&m_dataMutex);
m_data = data;
pthread_mutex_unlock(&m_dataMutex);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.