User:jeyrb: jey's network's del.icio.us bookmarks
Software
Programming
tutorials
parallel
threads
multithreading
User:jeyrb
Programming
messaging
Book
reference
Tutorial
threads
concurrency
For the past 2 weeks, I’ve been wrestling with a fix for task 208487. At first glance, it seems pretty far-fetched (at least it did to me): an application that has 2 billion running timers and runs out of timer ids. But then I went and looked at the code (that I wrote!) and the real problem slapped me in the face: any application can only ever start 2 billion timers in total (which is different from having 2 billion concurrent timers). We never recycle timer ids. That means that the following code will quit working after 24.85 days. If we change the timeout to be zero instead, the runtime is reduced to hours instead of days.
class Object : public QObject
{
Q_OBJECT
public:
Object() : QObject() { QTimer::singleShot(1, this, SLOT(timeout())); }
public slots:
void timeout() { QTimer::singleShot(1, this, SLOT(timeout())); }
};
After quickly rejecting the question “Should I fix this?” (of course I should!), I promptly got my hands dirty looking for a solution. Fixing this proved to be harder than I originally anticipated…