GUI update from another thread

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
r3d3
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Oct 16, 2007 10:53 am

GUI update from another thread

Post by r3d3 »

Hi everyone,

I read all the posts for this problem here, but I cannot solve my problem.

The thing is that I am making a SDK - I don't have a main thread to perform GUI events with PostEvent.
In one of the functions I pop up wxDialog and I show images from real time camera.
So wxWidets is used at this function only and it is running in one of the threads that I have.
Before I create the dialog I create IMPLEMENT_APP_NO_MAIN wxApp and than I use wxMutexGuiEnter/wxMutexGuiLeave to perform GUI relates stuff.
On Windows with MinGW this works perfectly fine.
But now I need to port the code to Linux with GTK+ and I get deadlock when wxMutexGuiEnter/wxMutexGuiLeave is used. I am not able to get the dialog running from another thread.

I also did experiments - main thread with wxApp- IMPLEMENT_APP and wxMutexGuiEnter/wxMutexGuiLeave works fine on Linux with GTK.
So it looks to me that wxMutexGuiEnter/wxMutexGuiLeave goes in deadlock only when the main thread is not wxWigdets related.

I am aware that this is not wxWigets specific but I need to find solution.

Any suggestions will be greatly appreciated.
Thanks
megabyte
I live to help wx-kind
I live to help wx-kind
Posts: 196
Joined: Tue Dec 07, 2004 8:54 pm
Location: Essen, Germany

Post by megabyte »

I don't see any problem to use threads in a library which has no main thread. The library is used in an application which has a main thread and a messages loop.
r3d3
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Oct 16, 2007 10:53 am

Post by r3d3 »

megabyte wrote:I don't see any problem to use threads in a library which has no main thread. The library is used in an application which has a main thread and a messages loop.
Thanks for the reply.

I don't have problem using the threads, I have problem to do GUI related stuff from the thread.
This is a SDK so the application which has a main thread and a message loop is not in my hands.
When this function is called another thread is created, in which I have to show this dialog, show some real time images taken from camera and close it at the end of the function.
r3d3
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Oct 16, 2007 10:53 am

Post by r3d3 »

Anyone suggestions, please?

Thanks
Lloyd
Super wx Problem Solver
Super wx Problem Solver
Posts: 350
Joined: Wed May 03, 2006 2:36 pm
Location: India
Contact:

Post by Lloyd »

But now I need to port the code to Linux with GTK+ and I get deadlock when wxMutexGuiEnter/wxMutexGuiLeave is used. I am not able to get the dialog running from another thread.
I would like to quote this from the documentation
void ::wxMutexGuiEnter()
....
...
Note that under GTK, no creation of top-level windows is allowed in any thread but the main one.

This function is only defined on platforms which support preemptive threads.
I am not sure whether this would be helpful to you...
r3d3
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Oct 16, 2007 10:53 am

Post by r3d3 »

Hi Lloyd,

I read that and tried to create the dialog using wxDIALOG_NO_PARENT flag and NUll for parent window.
I also check that I do not use SetTopWindow function.

But it didn't help.

Regards
Lloyd
Super wx Problem Solver
Super wx Problem Solver
Posts: 350
Joined: Wed May 03, 2006 2:36 pm
Location: India
Contact:

Post by Lloyd »

My above post just means that in GTK, threads cannot create a top level window (Frame and Dialog) even if you use wxMutexGuiEnter/wxMutexGuiLeave
Post Reply