Page 1 of 1

Threads in dll

Posted: Wed Aug 04, 2010 9:26 am
by johnnie
Hi all,

I have non GUI class which can be used by any of the wxWidgets application. I need to create a dynamic library.

Code: Select all

class ConfigClient: public wxThread
{
public:

	ConfigClient(void);
	virtual ~ConfigClient(void);
	static ConfigClient *getConfigInstance(int sessionId = 0);
	static void closeConfigInstance(int sessionId = 0);

        void initialize(void);
	virtual void OnExit(void);
	void unsubscribe();
        void *Entry(void);

private:

	wxSocketClient* m_pBroadcastSocket;
	wxSocketClient* m_pGetSetSocket;
	wxCriticalSection m_socketCritsect;
	ConditionList m_conditionList; 
	wxCriticalSection m_listCritsect;
	wxSemaphore m_semThreadInit;
	wxCondition *m_condThreadEnd;
};

void *ConfigClient::Entry(void)
{
       m_semThreadInit.Post();
       while (1)
       { 
             // do something
             // write data on the socket
       }
}

void ConfigClient::initialize(void) 
{
 
        // create get/set socket
        // create m_pBroadcastSocket

        /*Create a thread, inside thread create a new client socket for broadcasting messages*/
        if(Create() ==  wxTHREAD_NO_ERROR)
        {
        	threadError = Run();
        	m_semThreadInit.Wait();
         }
	        
}
ConfigClient* ConfigClient ::getConfigInstance(int sessionId)
{
	if ( NULL == m_configInstanceMap )
	{
		m_configInstanceMap = new configInstanceMap();
	}
	if ( (*m_configInstanceMap)[sessionId] == NULL)
	{
		(*m_configInstanceMap)[sessionId]= new ConfigClient();
	}
	return (*m_configInstanceMap)[sessionId];
}
From some wxWidget application

Code: Select all


	ConfigClient *m_pcfgClient = ConfigClient::getConfigInstance(0);
	
	m_pcfgClient->initialize();
My question is that how do I make the ConfigClient class dynamic. Can we have threads in dll. If I use threads in dll onExit is called from wxWidgets library.

Please help !

Regards
Johnnie