< Previous by Date Date Index Next by Date >
  Thread Index  

[reSIProcate-users] DUM and thread safety


Hi,
 
I'm using resiprocate to build a simple IM. So far I've been testing it mainly in a cmd line environment using a single thread. Now I'd like to start with the GUI and so I'm looking at threading. I'm completely new to resiprocate though and I haven't written a lot of multithreaded programs in the past so I'm unsure how to proceed. I've looked at the wiki but there's a few things that I don't understand.
 
Using or replicating DumThread seems the easiest to me, but as I understand it, this class needs to be augmented with a mutex lock on it's thread() function. So I was thinking of implementing my own class. Something along the lines of (using Qt):
 
class MyDumThread : public QThread
{
Q_OBJECT
public:
MyDumThread(DialogUsageManager& dum);
mutable QMutex mutex;
protected:
void run();
private:
DialogUsageManager& mDum;
};
 
void MyThread::run()
{
while (true)
{
try
{
std::auto_ptr<Message> msg(mDum.mFifo.getNext(1000)); // Only need to wake up to see if we are shutdown
if (msg.get())
{
QMutexLocker locker(&mutex); // locked here by constructor
mDum.internalProcess(msg);
} // unlocked here by destructor (?)
}
catch (BaseException& e)
{
WarningLog (<< "Unhandled exception: " << e);
}
}
}
 
And any calls to the mDum object preceded by "QMutexLocker locker(&theMyDumThreadMutex);", like:
 
void MyClass::go()
{
QMutexLocker locker(&theMyDumThreadMutex);
theMyDumThreadDum->send(...);
}
 
Would this be safe? Is this a correct implementation?
Also, (and this is more of a Qt question I guess) I was thinking about, as an alternative, simply connecting a QTimer's timeout signal to a slot that has the single threaded code in it. Like:
void TimeOutSlot()
{
while (!dumShutDown)
{
     FdSet fdset;
     stack->buildFdSet(fdset);
     int err = fdset.selectMilliSeconds(stack->getTimeTillNextProcessMS());
     assert ( err != -1 );
     stack->process(fdset);
     while(dumUas->process());
}
}
But I am not familiar with Qt's inner workings in regards to how the timer works (i.e. does it use it's own thread?).
 
Any feedback is greatly appreciated.


het ultieme online mailprogramma! Ontdek Windows Live Hotmail,