problem with wxMutex accessing

Lloyd lloyd at cdactvm.in
Mon Nov 5 02:04:57 PST 2007


Hi,
I have a multi threaded program to search in files. A status bar derived
class has a global data which is used by the main thread only. The
vector is updated (add, remove and access) by different events. To solve
mutual exclusion I use wxMutex as follows. 

really do I need to have mutual exclusion (wxMutex) in this case? If I
dont use mutual exclusion, the code crashes!  

class MainStatusBar:public wxStatusBar
{
	....
	....
	private:
		wxMutex s_std; 
		vector<SearchThreadData> std; //The global data
	....	
};

The status bar has so many gauges to show the search status. I am
capturing the right click event and tries to access the mutex using the
following code...

 wxMutexError er=s_std.Lock();

 if(er==wxMUTEX_BUSY )
 {
  	wxMessageBox(wxT("Mutex busy"));
 }
 else if(er==wxMUTEX_NO_ERROR)
 {
	  wxMutexError er=s_std.Unlock();
	  wxMessageBox(wxT("Mutex no error"));
 }
 else if(er==wxMUTEX_DEAD_LOCK)
 {
	  wxMessageBox(wxT("Mutex deadlock"));
 }
 else
 {
	  wxMessageBox(wxT("default"));
 }


 In this case it shows the "default" message!! I tried it with TryLock()
as well. the same thing happens!  But in other areas no problem is there
in accessing the mutex using wxMutexLocker or wxMutex::Lock(). The only
special thing which i do is in the creation time of a new gauge I
connect it with the event handler as follows (this too from the main
thread)

wxGauge* g=new wxGauge(this,wxID_ANY,100);
g->Connect(wxID_ANY,wxEVT_RIGHT_DOWN,wxMouseEventHandler
(MainStatusBar::OnRightClick)); //Is connecting wxID_ANY is wrong?

I am not at all able find out the reason for this :( Would you give me
some hints?

Thank you very much,
 
 Lloyd 




______________________________________
Scanned and protected by Email scanner




More information about the wx-users mailing list