WxThreads

From Audacity Wiki
Jump to: navigation, search


  • Mchinen Did a test to check wxMac priorities. Turns out they do work, but threads at min priority only go about 10% slower than the default priority, and only 20% slower than the max priority:
if someone wants to try it out and paste the linux result, that
would be helpful.  I've included the changes you need to make to the sample in wx2.8.7/samples/thread/thread.cpp I made to avoid
Sleep(1000) for each thread and to do a huge nothing loop instead.


Thread 0x1878200 started (priority = 0).
[0] Thread 0x1878200 here.
Thread 0x1861a00 started (priority = 50).
[0] Thread 0x1861a00 here.
[1] Thread 0x1878200 here.
[1] Thread 0x1861a00 here.
[2] Thread 0x1878200 here.
[2] Thread 0x1861a00 here.
[3] Thread 0x1878200 here.
[3] Thread 0x1861a00 here.
[4] Thread 0x1878200 here.
[4] Thread 0x1861a00 here.
[5] Thread 0x1878200 here.
[5] Thread 0x1861a00 here.
[6] Thread 0x1878200 here.
[6] Thread 0x1861a00 here.
[7] Thread 0x1878200 here.
[7] Thread 0x1861a00 here.
[8] Thread 0x1878200 here.
[8] Thread 0x1861a00 here.
[9] Thread 0x1878200 here.
[9] Thread 0x1861a00 here.
Thread 0x1878200 finished.
Thread 0x1861a00 finished.

trial 2:
Thread 0x1861600 started (priority = 100).
Thread 0x186b400 started (priority = 50).
Thread 0x1846e00 started (priority = 50).
[0] Thread 0x1861600 here.
Thread 0x186ee00 started (priority = 0).
[0] Thread 0x1846e00 here.
[0] Thread 0x186b400 here.
[0] Thread 0x186ee00 here.
[1] Thread 0x1861600 here.
[1] Thread 0x1846e00 here.
[1] Thread 0x186b400 here.
[1] Thread 0x186ee00 here.
[2] Thread 0x1861600 here.
[2] Thread 0x1846e00 here.
[2] Thread 0x186b400 here.
[2] Thread 0x186ee00 here.
[3] Thread 0x1861600 here.
[3] Thread 0x1846e00 here.
[3] Thread 0x186b400 here.
[4] Thread 0x1861600 here.
[3] Thread 0x186ee00 here.
[4] Thread 0x186b400 here.
[4] Thread 0x1846e00 here.
[5] Thread 0x1861600 here.
[4] Thread 0x186ee00 here.
[5] Thread 0x186b400 here.
[5] Thread 0x1846e00 here.
[6] Thread 0x1861600 here.
[5] Thread 0x186ee00 here.
[7] Thread 0x1861600 here.
[6] Thread 0x1846e00 here.
[6] Thread 0x186b400 here.
[8] Thread 0x1861600 here.
[7] Thread 0x1846e00 here.
[7] Thread 0x186b400 here.
[6] Thread 0x186ee00 here.
[9] Thread 0x1861600 here.
[8] Thread 0x1846e00 here.
[8] Thread 0x186b400 here.
[7] Thread 0x186ee00 here.
Thread 0x1861600 finished.
[9] Thread 0x1846e00 here.
[9] Thread 0x186b400 here.
[8] Thread 0x186ee00 here.
Thread 0x1846e00 finished.
Thread 0x186b400 finished.
[9] Thread 0x186ee00 here.
Thread 0x186ee00 finished.


void *MyThread::Entry()
{
   wxString text;

   text.Printf(wxT("Thread 0x%lx started (priority = %u).\n"),
               GetId(), GetPriority());
   WriteText(text);
   // wxLogMessage(text); -- test wxLog thread safeness

   for ( m_count = 0; m_count < 10; m_count++ )
   {
       // check if we were asked to exit
       if ( TestDestroy() )
           break;

       text.Printf(wxT("[%u] Thread 0x%lx here.\n"), m_count, GetId());
       WriteText(text);

       //test priorities
       for(int i=0;i<1000000000;i++)
         i=i+0;
       // wxSleep() can't be called from non-GUI thread!
       //        wxThread::Sleep(1000);
   }

   text.Printf(wxT("Thread 0x%lx finished.\n"), GetId());
   WriteText(text);
   // wxLogMessage(text); -- test wxLog thread safeness

   return NULL;
}