I'm using a pthread, that at the moment, is sleeping for 1 second then writing to a log file and printing to the screen. In my int main(), there's a while loop that runs forever right now, but will eventually stop. In the loop, it's accessing the logger, which is my singleton class, writing to it, and printing to the screen as well. Here's the logger get instance funciton...
Logger* Logger::getInstance(){
if(logger == NULL){
logger = new Logger();
}
return logger;
}
Here's the thread function that waits for a second...
void Beacon::send(){
while(1){
sleep(1);
Logger* logger = Logger::getInstance();
logger->log("Sending");
}
}
Here's the while loop that also prints to the logger. The checkQueue funciton doesn't do anything right now...
while(!a){
logger->getInstance()->log("Checking...");
checkQueue();
if(a == true)
break;
}
When I have it logging in the while loop, It will only print checking to the screen. When I comment that out, it will print sending to the screen. Do I need to have a double lock check in the get instance function? I've been trying to look into that, but don't understand how to implement it.