The implementations for singleton patterns are not
thread safe. This means that it is possible to obtain
more than one instance of a category object across two threads. Especially since it is not a rare case that the static getInstance is called upon the Category object to obtain the category that is to be logged to.
example: (double locked pattern)
object& getInstance()
{
// create when called.
static pthread_mutex_t = PTHREAD_MUTEX_INITIALIZER;
if (Object == 0)
{
// this should be fast, because this
// point is only locked the first time.
pthread_mutex_lock(&mutex);
if (Object == 0)
{
m_Instance = new object;
}
pthread_mutex_unlock(&mutex);
}
}
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The implementations for singleton patterns are not
thread safe. This means that it is possible to obtain
more than one instance of a category object across two threads. Especially since it is not a rare case that the static getInstance is called upon the Category object to obtain the category that is to be logged to.
example: (double locked pattern)
object& getInstance()
{
// create when called.
static pthread_mutex_t = PTHREAD_MUTEX_INITIALIZER;
if (Object == 0)
{
// this should be fast, because this
// point is only locked the first time.
pthread_mutex_lock(&mutex);
if (Object == 0)
{
m_Instance = new object;
}
pthread_mutex_unlock(&mutex);
}
}
}