wxThread exits in windows

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
johnnie
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Jan 14, 2008 8:59 am
Location: Bangalore
Contact:

wxThread exits in windows

Post by johnnie » Fri Jul 09, 2010 9:48 am

Hi all,

I am porting an application from Linux to windows which uses wxWidgets. I was able to compile and bring up the application in windows with some issues. I need your help in resolving the same. I have created a dynamic library for creating a secondary thread. The secondary thread exits for no reason. Please find below the traces from GDB.

Code: Select all

8 ConfigClient::OnExit() D:\xxxx_porting\yyyyy\xxx\dynlib\fwconfigClt\src\fwConfigclient.cpp:1240 0x6f3c4096	
7 wxThreadInternal::DoThreadOnExit()  0x6f48fcf4	
6 void wxPrivate::OnScopeExit<wxScopeGuardImpl1<void (*)(wxThread*), wxThread*> >()  0x6f4f26e5	
5 wxThreadInternal::DoThreadStart()  0x6f49156e	
4 wxThreadInternal::WinThreadStart()  0x6f491634	
3 msvcrt!_endthreadex()  0x77c3a3b0	
2 KERNEL32!GetModuleFileNameA()  0x7c80b729	
1 <symbol is not available> 0x00000000	
[/code]
--johnniealan --

johnnie
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Jan 14, 2008 8:59 am
Location: Bangalore
Contact:

Post by johnnie » Fri Jul 09, 2010 11:35 am

Hi all,

Adding to the above query. The thread is created after creating a client socket.

Code: Select all

if (NULL == m_pGetSetSocket)
{
	/* Create the socket*/
	m_pGetSetSocket = new wxSocketClient();
	if (NULL == m_pGetSetSocket)
	{
		return E_RET_ERROR;
	}
	m_pGetSetSocket->SetFlags(wxSOCKET_BLOCK);
	do
	{
		m_pGetSetSocket->Connect(stAddr,true);
        	if (FALSE == m_pGetSetSocket->IsConnected()) 
	        {
    	              m_pGetSetSocket->Destroy();
        	      delete m_pGetSetSocket;
            	      m_pGetSetSocket = NULL;
	              eCode = E_RET_ERROR;
		      return eCode;
        	}
	}while(!m_pGetSetSocket->IsConnected());

    /*Create a thread, inside thread create a new client socket for broadcasting messages*/
    if(Create() ==  wxTHREAD_NO_ERROR) 
    {
        threadError = Run();
	m_isInitialized = TRUE;
    }
    else
    {
        eCode = E_RET_ERROR;
    }
}
Is this is a known issue ?

Regards
Johnnie
--johnniealan --

User avatar
doublemax
Moderator
Moderator
Posts: 15507
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Fri Jul 09, 2010 12:28 pm

It would have been more interesting to see the code of the thread itself.

Did you put some debug output inside your thread code? It's hard to believe that a thread is just killed out of nowhere, it's more likely it exits "normally" by one of the exit conditions in your code.
Use the source, Luke!

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Fri Jul 09, 2010 12:35 pm

Hi,

can we see your thread entry function? From reading the code related to your stack trace, it seems like the thread exits because your thread entry method returned.
"Keyboard not detected. Press F1 to continue"
-- Windows

johnnie
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Jan 14, 2008 8:59 am
Location: Bangalore
Contact:

Post by johnnie » Sat Jul 10, 2010 5:26 am

Hi,

Thanks for your valuable inputs. I will explain the complete scenario.

I have two process, the first one is called master and the second one is configuration server. When the application comes up the configuration server is started and master connects to the configuration server through the client called config client.

The config client is a singleton class which exposes two API's one for creating the object and another for creating a socket client plus a listening thread .Configuration client is linked as a dynamic library with master process.

In order to find the bug, I modified config client entry function to have only single trace. Even with this simple code the thread exits and closes the client socket by itself.

Moreover the same code ( creating a client socket and listening thread ) implemented in the master process itself works fine.

Is this something to do with the dynamic linking?

wxWidgets 2.8.11 has been linked statically with my application.

Code: Select all

Code for configlclient:
void *ConfigClient::Entry(void)
{
	logDebugMsg(__FILE__,__LINE__,wxT("configClient:: Thread entry poin function"));
	while(1){};
}

Code: Select all

Logs
10:30:51: SESSION 0:CONFIGURATION SERVER :cfgConfigserver.cpp:315:ConfigServer:: Configuration server socket is created and listening on port 4987.
10:30:51: SESSION 0:CONFIGURATION SERVER :cfgConfigserver.cpp:338:config Server: sem post is success: No error
10:30:51: SESSION 0:CONFIGURATION SERVER :cfgConfigserver.cpp:181:ConfigServerApp: New configuration object is created successfully for the configuration port 4987
10:30:54: SESSION 0:MASTER :test.cpp:91:Config Server started at port (4987) with process id (3488) 
10:31:56: SESSION 0:MASTER :fwConfigclient.cpp:173:configClient:: Initializing the Config client for the process 3 for the configuration port 4987
10:32:03: SESSION 0:MASTER :fwConfigclient.cpp:253:configClient::Connection established with server
10:27:19: SESSION 0:MASTER :fwConfigclient.cpp:1266:configClient Broadcasting thread Destroyed. OnExit()
wxWidgets version : 2.8.11
Platform : windows
IDE : eclipse - galeleo
Compiler : mingw, g++ 4.5
Binutils : 2.20

Regards
Johnnie
--johnniealan --

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Sat Jul 10, 2010 2:48 pm

Is that your real code you posted??
Perhaps you can post a more complete example, I'm sorry but I don't really make sense of the entry function you posted
(e.g. I can't see the log line in the log you posted; do you mean that the thread entry method is not called at all?)
"Keyboard not detected. Press F1 to continue"
-- Windows

johnnie
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Jan 14, 2008 8:59 am
Location: Bangalore
Contact:

Post by johnnie » Mon Jul 12, 2010 7:00 am

Hi,
Auria wrote:Is that your real code you posted??
I have simplified my code for testing purpose.
Auria wrote: (e.g. I can't see the log line in the log you posted; do you mean that the thread entry method is not called at all?)
Yes the entry functions of thread is not called. Before calling the entry function, wxWidgets gets an exception so it exits the thread.

The same code if linked statically works fine with no issues.

Is wxWidgets in windows doesn't go well with dynamic linking. Ex: If wxWidgets libraries are linked dynamically linker throws the following error:

Code: Select all

(.rdata$_ZTV15wxStaticBoxBase[vtable for wxStaticBoxBase]+0xec): undefined reference to `wxWindow::Reparent(wxWindowBase*)
Please help.
--johnniealan --

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Mon Jul 12, 2010 4:33 pm

johnnie wrote: Yes the entry functions of thread is not called. Before calling the entry function, wxWidgets gets an exception so it exits the thread.
Ah, very different beast then. What you need to do here is to check which exception it is, "an" exception is not sufficient
johnnie wrote:

Code: Select all

(.rdata$_ZTV15wxStaticBoxBase[vtable for wxStaticBoxBase]+0xec): undefined reference to `wxWindow::Reparent(wxWindowBase*)
do you use the MinGW compiler?
Perhaps post the command line you use to link your application, likely your linking is not done correctly
"Keyboard not detected. Press F1 to continue"
-- Windows

johnnie
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Jan 14, 2008 8:59 am
Location: Bangalore
Contact:

Post by johnnie » Tue Jul 13, 2010 8:55 am

Hi,

The Function doThreadStart uses the macro wxON_BLOCK_EXIT1 for registering the Exit function.

Code: Select all

thread.cpp
/* static */
THREAD_RETVAL wxThreadInternal::DoThreadStart(wxThread *thread)
{
    wxON_BLOCK_EXIT1(DoThreadOnExit, thread);
wxScopeGuardImpl1 destructor is called by the compiler which invokes wxPrivate::OnScopeExit. The Problem is not the with code which I wrote. The code sample doesn't have kill or Exit neither.

Code: Select all

  from scopeguard 
~wxScopeGuardImpl1() { wxPrivateOnScopeExit(* this); }
I tried with CreateThread function in windows ( dll ). It works perfectly fine.

Can you please give me a solution for the same.

Regards
Johnnie
Last edited by johnnie on Thu Jul 15, 2010 4:41 am, edited 1 time in total.
--johnniealan --

johnnie
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Jan 14, 2008 8:59 am
Location: Bangalore
Contact:

Post by johnnie » Tue Jul 13, 2010 10:30 am

Hi all,

I am attaching the sample application along with this post for your reference.

Please help in this regard.

Moreover I am not able to create a import library (.lib) for the dll.

Regards
Johnnie
Attachments
send_to_forum.rar
(7.86 KiB) Downloaded 57 times
--johnniealan --

johnnie
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Jan 14, 2008 8:59 am
Location: Bangalore
Contact:

Post by johnnie » Wed Aug 04, 2010 11:37 am

anyone to help ?
--johnniealan --

Post Reply