Click here to Skip to main content
15,902,198 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Dialog Resize Pin
Paolo Messina14-Sep-01 4:46
professionalPaolo Messina14-Sep-01 4:46 
Questionhow to enumerate all the .txt files in some directory? Pin
phped13-Sep-01 20:24
phped13-Sep-01 20:24 
AnswerRe: how to enumerate all the .txt files in some directory? Pin
Ben M. Stokland13-Sep-01 21:36
Ben M. Stokland13-Sep-01 21:36 
Generalverify existency of URL ( with proxy ) Pin
13-Sep-01 18:18
suss13-Sep-01 18:18 
GeneralRe: verify existency of URL ( with proxy ) Pin
A.R.14-Sep-01 0:08
A.R.14-Sep-01 0:08 
GeneralText Area With Multiline Pin
yccheok13-Sep-01 17:40
yccheok13-Sep-01 17:40 
GeneralRe: Text Area With Multiline Pin
Steen Krogsgaard13-Sep-01 21:26
Steen Krogsgaard13-Sep-01 21:26 
GeneralMultithreading with GUI hang up problem Pin
yccheok13-Sep-01 17:38
yccheok13-Sep-01 17:38 
I face some problem in implementing a multithreading dialog based program (C/SDK) which used to simulate dining philosopher problem.
In my program, I create 6 threads using _beginthread() respectively where
the 5 threads is use to keep looping in an infinity loop, update their state and keep sending InvalidateRect() to a display control. It roughly look like this :
void Run( void *pParam)
{
while(ps->bRunnable)
{
Update Philosopher State
InvalidateRect(hwndCtl, NULL, TRUE);
UpdateWindow(hwndCtl); // hwndCtl is handle to subclassing
// control which has his own message
// procedure
}
}

one thread is responsible to keep track one the timing. When the time reach, it will stop the other 5 threads. It roughly look like this :

void RunSimulation(void *pParam)
{
start philosopher thread
while(time(0)-tTimeStart < nSimulation[nIndexSimulation] &&
bSimRunnable)
{
}

bSimRunnable = FALSE;
}

I start both threads with :
_beginthread(Run, 0, (void *)ps)
_beginthread(RunSimulation, 0, (void *)ps)

However, I totally lose my control on the GUI control. My mouse click on
the dialog box would not responde until all the threads finished. I try to clear the message in the queqe before philosopher thread further sending any
message. I place the following code inside Run()
void Run( void *pParam)
{
// clear the message queqe before thread further send any message
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{ ///////////////////////////////////////////////
//BUT THE THREAD NEVER ENTER THIS BLOCK! WHY???
///////////////////////////////////////////////
// seperate dialog box message from null parent window
if( !IsDialogMessage(hDlgMain, &msg) &&
!IsDialogMessage(hDlgCon, &msg) &&
!IsDialogMessage(hDlgGraph, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg); // send to null parent
}

}

while(ps->bRunnable)
{
Update Philosopher State
InvalidateRect(hwndCtl, NULL, TRUE);
UpdateWindow(hwndCtl); // hwndCtl is handle to subclassing
// control which has his own message
// procedure
}
}
----------------------------------------------------------------------------
This won't work and the dialog box still hang up
while the threads is running.

Pls help. If possible, do e-mail the solution to my mail box
yccheok@yahoo.com

since i don't have any internet access in this few day and it may take my sometimes to search back my message Smile | :)

thanks

regards
yccheok
GeneralRe: Multithreading with GUI hang up problem Pin
Tomasz Sowinski14-Sep-01 0:21
Tomasz Sowinski14-Sep-01 0:21 
GeneralZorder Pin
JekYu13-Sep-01 15:15
JekYu13-Sep-01 15:15 
GeneralRe: Zorder Pin
Christian Graus13-Sep-01 16:08
protectorChristian Graus13-Sep-01 16:08 
GeneralRe: Zorder Pin
JekYu13-Sep-01 16:32
JekYu13-Sep-01 16:32 
GeneralRe: Zorder Pin
13-Sep-01 18:26
suss13-Sep-01 18:26 
GeneralI need to disable ESC key in ATL COM CAxDialogImpl... Pin
Matt Philmon13-Sep-01 13:50
Matt Philmon13-Sep-01 13:50 
GeneralRe: I need to disable ESC key in ATL COM CAxDialogImpl... Pin
Ben M. Stokland13-Sep-01 21:13
Ben M. Stokland13-Sep-01 21:13 
GeneralRe: I need to disable ESC key in ATL COM CAxDialogImpl... Pin
Matt Philmon14-Sep-01 4:20
Matt Philmon14-Sep-01 4:20 
GeneralHELP Pin
DanYELL13-Sep-01 12:35
DanYELL13-Sep-01 12:35 
GeneralRe: HELP Pin
Michael P Butler13-Sep-01 22:11
Michael P Butler13-Sep-01 22:11 
GeneralColoring text in an ATL Control Pin
lpvoid13-Sep-01 12:11
lpvoid13-Sep-01 12:11 
GeneralRe: Coloring text in an ATL Control Pin
Erik Thompson13-Sep-01 12:41
sitebuilderErik Thompson13-Sep-01 12:41 
GeneralReading and writing bits. Pin
kakuni13-Sep-01 11:40
kakuni13-Sep-01 11:40 
GeneralRe: Reading and writing bits. Pin
Carlos Antollini13-Sep-01 11:48
Carlos Antollini13-Sep-01 11:48 
GeneralRe: Reading and writing bits. Pin
kakuni13-Sep-01 12:14
kakuni13-Sep-01 12:14 
GeneralRe: Reading and writing bits. Pin
User 988513-Sep-01 11:54
User 988513-Sep-01 11:54 
GeneralRe: Reading and writing bits. Pin
kakuni13-Sep-01 12:15
kakuni13-Sep-01 12:15 

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.