Author Topic: UI thread to build the symbol tree  (Read 10792 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
UI thread to build the symbol tree
« on: August 06, 2011, 10:06:53 am »
I found that this function is running in a separate thread instead the main thread.
Code
void* ClassBrowserBuilderThread::Entry()
{
    while (!TestDestroy() && !Manager::IsAppShuttingDown())
    {
        // wait until the classbrowser signals
        m_Semaphore.Wait();
//        Manager::Get()->GetLogManager()->DebugLog(F(_T(" - - - - - -")));

        if (TestDestroy() || Manager::IsAppShuttingDown())
            break;

        if (platform::gtk)
        {
            // this code (PART 1/2) seems to be good on linux
            // because of it the libcairo crash on dualcore processors
            // is gone, but on windows it has very bad influence,
            // henceforth the ifdef guard
            // the questions remains if it is the correct solution
            if (!::wxIsMainThread())
                ::wxMutexGuiEnter();
        }

        BuildTree();

        if (platform::gtk)
        {
            // this code (PART 2/2) seems to be good on linux
            // because of it the libcairo crash on dualcore processors
            // is gone, but on windows it has very bad influence,
            // henceforth the ifdef guard
            // the questions remains if it is the correct solution
            if (!::wxIsMainThread())
                ::wxMutexGuiLeave();
        }
    }

    m_NativeParser = 0;
    m_TreeTop = 0;
    m_TreeBottom = 0;

    return 0;
}

Does it safe to manipulate UI from a separate thread???
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: UI thread to build the symbol tree
« Reply #1 on: August 06, 2011, 10:33:23 am »
On gtk the wxMutexGuiEnter and wxMutexGuiLeave should make it sure, why it is not used on other platforms, I don't know.
"very bad influence" as cause for not using it on windows is nor really an exact explanation.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: UI thread to build the symbol tree
« Reply #2 on: August 06, 2011, 10:57:29 am »
thanks for the reply.
Also, I found a relative topic. see:
Re: Help on wxWidgets multi threading management

Edit:
see what wx developers said:
http://forums.wxwidgets.org/viewtopic.php?f=1&t=21037&hilit=wxMutexGuiEnter
Quote
i always considered wxMutexGuiEnter more like a hack. There is discussion among the wx developers to remove it completely.

I recommend not to use it.


edit2:
I search on the c::b's source(include all the plugins source), the only place use "wxMutexGuiEnter" is here, I guess this is not a good design.
« Last Edit: August 06, 2011, 11:26:50 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: UI thread to build the symbol tree
« Reply #3 on: August 28, 2011, 10:59:48 am »
Can we build the symbols tree on MAIN Thread?
Any comments?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: UI thread to build the symbol tree
« Reply #4 on: August 28, 2011, 11:06:00 am »
Can we build the symbols tree on MAIN Thread?
Any comments?
Building the symbols-tree can take several seconds and would block the main-thread every time it is rebuild.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: UI thread to build the symbol tree
« Reply #5 on: August 28, 2011, 11:14:23 am »
Can we build the symbols tree on MAIN Thread?
Any comments?
Building the symbols-tree can take several seconds and would block the main-thread every time it is rebuild.
But now there is a multi-thread-safety issues!
If we delete a Parser, but the symbol tree is still in the build process?

I can't find a better way for solved this issue.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: UI thread to build the symbol tree
« Reply #6 on: August 28, 2011, 11:19:35 am »
You can use shared_ptr to prevent the deletion.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: UI thread to build the symbol tree
« Reply #7 on: August 28, 2011, 12:01:19 pm »
You can use shared_ptr to prevent the deletion.
and additional a flag, that marks the parser as invalid, so the symbolsbrowser buildthread (or possibly others that use the parser) stop using it.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: UI thread to build the symbol tree
« Reply #8 on: August 28, 2011, 02:51:49 pm »
You can use shared_ptr to prevent the deletion.
and additional a flag, that marks the parser as invalid, so the symbolsbrowser buildthread (or possibly others that use the parser) stop using it.
This is a lot of trouble! Seems to be slowly improved.
If more developers can focus CC plug-in, will be very lucky! :lol: