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

[reSIProcate-users] waiting for multithreaded DUM to process all queued commands before exit


I have used the solution as described in the wiki for making a seperate DUM thread and posting commands to it to keep it thread safe. But I'm having problems when exiting my application. Basically I want to unregister/end calls/etc before I exit.
 
When I post the unregister command however, it doesn't get processed as the DUM shuts down too soon (at least that's what I think is happening). How can I make sure any commands in the queue will be processed (sent) before the DUM actually shuts down? I've tried various combinations of waitForShutdown etc, but nothing seems to work 100% correctly.
 
Here's some of my code:
 
// start here
MainWindow::~MainWindow()
{
    m_localUser.Unregister(m_pDum, m_rHandler.m_registerHandle);
    StopSip();
}
 
void LocalUser::Unregister(DialogUsageManager* dum, ClientRegistrationHandle handle)
{
    if(handle.isValid())
    {
        UnregisterDumCommand* cmd =
new UnregisterDumCommand(dum, handle);
        dum->post(cmd);
    }
}
 
void UnregisterDumCommand::executeCommand()
{
    cout << endl <<
"Unregistering..." << endl;
    m_handle->end();
}
 
void MainWindow::StopSip()
{
    // how can I wait here properly till all posted commands execute?
    m_pStackThread->shutdown();
    m_pStackThread->waitForShutdown(500);

    if(m_pDumThread)
    {
        m_pDumThread->shutdown();
        m_pDumThread->waitForShutdown(500);

    }
    m_pStackThread->join();
    if(m_pDumThread)
    {
        m_pDumThread->join();
        delete m_pDumThread;
    }
    if(m_pDum)
    {
        delete m_pDum;
    }
    if(m_pStackThread)
    {
        delete m_pStackThread;
    }

}
 
Also, I'm assuming I can use handles to execute functions without having it be thread unsafe? Only DUM-> calls need to be "posted" yes?
 
And lastly, I'm having some trouble getting a proper IP to paste into my SDP file on which people can contact me. I thought I could use the IP that is returned to me on a regiter command for this, but I seem to be getting my local IP on at least one computer.
 
 
Thanks in advance!


het ultieme online mailprogramma! Ontdek Windows Live Hotmail,