wxThread - why my code don`t work on mac? Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

wxThread - why my code don`t work on mac?

Post by lester » Thu Dec 21, 2006 10:22 am

I have problem with thread on mac with this code:

Code: Select all

class MyThread : public wxThread
{
public:
	MyThread( void );

	// thread execution starts here
	virtual void *Entry();

	// called when the thread exits - whether it terminates normally or is
	// stopped with Delete() (but not when it is Kill()ed!)
	virtual void OnExit() {}
}; 


/**********************************************************************************************/
MyThread::MyThread( void )
: wxThread()
{
}

/**********************************************************************************************/
void *MyThread::Entry()
{
....
// Get data from lan
...
			wxMutexGuiEnter();
                           // Append connection and show it
			t_pCtrl->AppendConnection( tConnection, false );
			wxMutexGuiLeave();
...
// Clean data
....
	return NULL;
}
 

bool MyApp::OnInit(void)
{
...
  MyThread* tThread = new MyThread();
  tThread->Create();
  tThread->Run();
...
}
After refresh gui I have crash in wx, but on win this code work fine, what I doing wrong?

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Thu Dec 21, 2006 11:39 am

Hi!
Hard to tell what the actual error is. Did you trace to see where exactly it crashes?

In general it is not advisable to update the GUI from another thread (although wxMutexGuiEnter is used). I'd advice you to create a custom event and send this event from the thread to the GUI to update using AddPendingEvent().
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester » Thu Dec 21, 2006 6:22 pm

Thanks, i try

Post Reply