Click here to Skip to main content
15,914,162 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralClipboard & Lines :: MFC Pin
valikac17-Sep-02 21:12
valikac17-Sep-02 21:12 
GeneralRe: Clipboard & Lines :: MFC Pin
Steve S17-Sep-02 21:24
Steve S17-Sep-02 21:24 
GeneralRe: Clipboard & Lines :: MFC Pin
includeh1017-Sep-02 21:23
includeh1017-Sep-02 21:23 
GeneralRe: Clipboard & Lines :: MFC Pin
valikac18-Sep-02 4:37
valikac18-Sep-02 4:37 
Questionwhat is wrong with my thread? help Pin
includeh1017-Sep-02 21:11
includeh1017-Sep-02 21:11 
in CDocument sub-class, i create a thread to access a buffer, at the CDocument closing time, sometimes a run-time happens. i don't know why.

coding as this:

class MyDoc: public CDocument
{
..................
//they are init as null in constructor
HANDLE hThread;
BOOL bLoop;
DWORD dwThreadID;
char*pBuf;
};


MyDoc:OnOpenDocument(...)
{
pBuf=new char [50000];
hThreat=CreateThread((LPSECURITY_ATTRIBUTES)0,0,
(LPTHREAD_START_ROUTINE)Proc_Thread,
this,0,&dwThreadID);
.........................
}

void MyDoc::OnCloseDocument()
{
bLoop=0;
if(hThread)CloseHandle(hThread);
if(dwThreadID)::PostThreadMessage(dwThreadID,WM_QUIT,0,0);
::WaitForSingleObject(hThread,(UINT)(-1));
delete []pBuf;
................................
}

int WINAPI Proc_Thread(void*pVoid)
{
MyDoc*p=(MyDoc*)pVoid;
char*pBuf=p->pBuf;
while(p->bLoop)
{
//access pBuf
}
return 1;
}

note: the only problem is at closing time.
is something wrong with the coding?

thx








includeh10
AnswerRe: what is wrong with my thread? help Pin
valikac17-Sep-02 21:17
valikac17-Sep-02 21:17 
GeneralRe: what is wrong with my thread? help Pin
Steve S17-Sep-02 21:27
Steve S17-Sep-02 21:27 
GeneralRe: what is wrong with my thread? help Pin
includeh1017-Sep-02 21:27
includeh1017-Sep-02 21:27 
GeneralRe: what is wrong with my thread? help Pin
Steve S17-Sep-02 22:02
Steve S17-Sep-02 22:02 
GeneralRe: what is wrong with my thread? help Pin
includeh1017-Sep-02 21:44
includeh1017-Sep-02 21:44 
GeneralRe: what is wrong with my thread? help Pin
valikac18-Sep-02 4:35
valikac18-Sep-02 4:35 
AnswerRe: what is wrong with my thread? help Pin
Stephane Rodriguez.17-Sep-02 22:09
Stephane Rodriguez.17-Sep-02 22:09 
GeneralHelp: ClassWizard error! Pin
Daniel Strigl17-Sep-02 20:38
Daniel Strigl17-Sep-02 20:38 
GeneralRe: Help: ClassWizard error! Pin
Steve S17-Sep-02 21:18
Steve S17-Sep-02 21:18 
GeneralRe: Help: ClassWizard error! Pin
Daniel Strigl17-Sep-02 21:39
Daniel Strigl17-Sep-02 21:39 
GeneralChange the bitmap of a CommandBand button... Pin
Daniel Strigl17-Sep-02 20:00
Daniel Strigl17-Sep-02 20:00 
GeneralUsing ShellExecute to send email Pin
Abin17-Sep-02 18:02
Abin17-Sep-02 18:02 
GeneralRe: Using ShellExecute to send email Pin
Shog917-Sep-02 19:19
sitebuilderShog917-Sep-02 19:19 
GeneralRe: Using ShellExecute to send email Pin
Abin17-Sep-02 20:17
Abin17-Sep-02 20:17 
GeneralRe: Using ShellExecute to send email Pin
Jon Hulatt17-Sep-02 22:15
Jon Hulatt17-Sep-02 22:15 
GeneralRe: Using ShellExecute to send email Pin
Stephane Rodriguez.17-Sep-02 22:16
Stephane Rodriguez.17-Sep-02 22:16 
GeneralRe: Using ShellExecute to send email Pin
Abin17-Sep-02 22:38
Abin17-Sep-02 22:38 

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.