Hi all,

Im writing a concurrent access queue. MY problem is that my producer is too much faster than the consumer, and the queue is allways filling up. I think that I have to write some congestion control, but sith sleeps? mutex?
One curious thing, if i write something like this:

void congestionControl (){

	std::stringstream logMessage;

	int pct=(messageQueue.size()*100)/maxQueueSize;
	if (pct>=LEVEL4_PERCENT_MESSAGES_READY){
		logMessage << "Aplying congestion control";
		LOG4CXX_DEBUG(logger,logMessage.str());
		sleep (1);
	}
}

If the sleep command is 1, the consumer allways can consum its messages, but if I write sleep (0.99) it cant. Why? any idea?


regards

sleep() takes whole integers. You can't pass 0.99 and expect it to do anything because 0.99 is converted to just 0. If you want to sleep less than one second then use nanosleep()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.