Click here to Skip to main content
15,917,618 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how will i get rid of that? Pin
Atilla Selem29-Apr-02 23:40
Atilla Selem29-Apr-02 23:40 
QuestionFirst Thread:IHTMLImgElement::put_src(BSTR) does not work? Pin
29-Apr-02 20:04
suss29-Apr-02 20:04 
GeneralBest Method for Screen Shot Pin
Sameer Maggon29-Apr-02 19:24
Sameer Maggon29-Apr-02 19:24 
GeneralRe: Best Method for Screen Shot Pin
Jon Sagara29-Apr-02 19:43
Jon Sagara29-Apr-02 19:43 
GeneralRe: Best Method for Screen Shot Pin
Christian Graus29-Apr-02 20:19
protectorChristian Graus29-Apr-02 20:19 
QuestionHow to programmaticly assign two NICs the same IP Pin
29-Apr-02 18:30
suss29-Apr-02 18:30 
AnswerRe: How to programmaticly assign two NICs the same IP Pin
Mike Nordell1-May-02 9:08
Mike Nordell1-May-02 9:08 
GeneralMajor Multithread Problem :: MFC Pin
valikac29-Apr-02 17:49
valikac29-Apr-02 17:49 
Hi.

I just found a major multithread bug a program I working on. First, I will describe the process that is causes the major multithread problem.

-----
- user opens a text file (any size) w/ text only
- user clicks an option in the menu
- view has a executes its message handler for the menu item
- view calls a function in doc
- doc begins a new thread (thread includes CSinglelock + CriticalSection, data from doc)
- thread resumes and begins processing the data
- when done, thread *PostMessage* mainframe that is done ::: -> AfxGetMainWnd->PostMessage(WM_USER_THREAD, 0, 0);
- main frame *SendMessage* to view ::: -> pView->SendMessage(WM_USER_THREAD, 0, 0)
- view calls a function in doc to close thread
- doc class this function
-----
////
// This function is called to close a thread
//
m_bThread = true; // meaning thread is still active

if (m_pThread && m_hThread) // m_hThread is a HANDLE to the thread
{
::WaitForSingleObject(m_hThread, INFINITE);
delete m_pThread;
m_pThread = NULL;
m_hThread = NULL;
m_bThread = false; // meaning thread has been closed

SetModifiedFlag(TRUE);
}

UpdateAllViews(NULL);
-----

Okay. Everything works good *if the use does not click anything* during the process. In other words, if the user were to click the menu or anything inside the window, the program would malfunction.

Notice the bool "m_bThread." I use it as an indicator about the status of the thread. if m_bThread is true, meaning that the thread is active, the program disables many options in the menu. These options will remain disabled unless m_nThread is false. For some reason, that variable remains *true* if the user starts clicks anyone in the menu or view processing. That means something is keeping the program to ever setting m_Thread to false. On the other hand, if the user does not click anything until after the process is over, everything works as planned.

I have no idea what is going on in the background. Is there a design flaw anywhere?

Thanks,
Kuphryn
GeneralRe: Major Multithread Problem :: MFC Pin
Neville Franks30-Apr-02 2:15
Neville Franks30-Apr-02 2:15 
GeneralRe: Major Multithread Problem :: MFC Pin
valikac30-Apr-02 4:05
valikac30-Apr-02 4:05 
GeneralRe: Major Multithread Problem :: MFC Pin
Neville Franks30-Apr-02 8:15
Neville Franks30-Apr-02 8:15 
GeneralRe: Major Multithread Problem :: MFC Pin
valikac30-Apr-02 11:44
valikac30-Apr-02 11:44 
GeneralRe: Major Multithread Problem :: MFC Pin
Neville Franks30-Apr-02 11:54
Neville Franks30-Apr-02 11:54 
GeneralRe: Major Multithread Problem :: MFC Pin
valikac30-Apr-02 12:00
valikac30-Apr-02 12:00 
GeneralRe: Major Multithread Problem :: MFC Pin
Neville Franks30-Apr-02 12:30
Neville Franks30-Apr-02 12:30 
GeneralRe: Major Multithread Problem :: MFC Pin
valikac30-Apr-02 12:35
valikac30-Apr-02 12:35 
GeneralRe: Possible Problem Pin
valikac30-Apr-02 12:59
valikac30-Apr-02 12:59 
GeneralRe: Possible Problem Pin
Neville Franks30-Apr-02 16:04
Neville Franks30-Apr-02 16:04 
QuestionLocale : do I get the wrong standard library????? Pin
Maxwell Chen29-Apr-02 17:23
Maxwell Chen29-Apr-02 17:23 
AnswerRe: Locale : do I get the wrong standard library????? Pin
Christian Graus29-Apr-02 17:40
protectorChristian Graus29-Apr-02 17:40 
GeneralRe: Locale : do I get the wrong standard library????? Pin
Maxwell Chen29-Apr-02 19:01
Maxwell Chen29-Apr-02 19:01 
GeneralRe: Locale : do I get the wrong standard library????? Pin
Christian Graus29-Apr-02 20:15
protectorChristian Graus29-Apr-02 20:15 
AnswerRe: Locale : do I get the wrong standard library????? Pin
Joaquín M López Muñoz29-Apr-02 21:01
Joaquín M López Muñoz29-Apr-02 21:01 
GeneralRe: Locale : do I get the wrong standard library????? Pin
Maxwell Chen29-Apr-02 22:57
Maxwell Chen29-Apr-02 22:57 
GeneralRe: Locale : do I get the wrong standard library????? Pin
Joaquín M López Muñoz29-Apr-02 23:09
Joaquín M López Muñoz29-Apr-02 23:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.