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

C / C++ / MFC

 
GeneralRe: Modifying MFC Pin
narendra_ b15-May-05 18:54
narendra_ b15-May-05 18:54 
GeneralRe: Modifying MFC Pin
jc0dex16-May-05 11:44
jc0dex16-May-05 11:44 
Generalusing a control from a .dll Pin
alex__b15-May-05 5:38
professionalalex__b15-May-05 5:38 
GeneralChanging the root in CFileDialog Pin
g_sol_115-May-05 3:48
g_sol_115-May-05 3:48 
GeneralRe: Changing the root in CFileDialog Pin
PJ Arends15-May-05 10:35
professionalPJ Arends15-May-05 10:35 
GeneralRe: Changing the root in CFileDialog Pin
g_sol_116-May-05 2:00
g_sol_116-May-05 2:00 
GeneralRe: Changing the root in CFileDialog Pin
PJ Arends16-May-05 7:23
professionalPJ Arends16-May-05 7:23 
GeneralThreads using up too much CPU Pin
15-May-05 3:47
suss15-May-05 3:47 
Hi,
I've written a piece of code that creates 10 threads (CreateThread) that poll 10 Transactional MSMQ message queues using MQReceiveMessage (check the url at the bottom). I've played around with the time out parameter in MQReceiveMessage. At the moment it's set to 5000ms??? (what value do you suggest?).

The same Message Queue code that I've written and I've used in a single threaded application works like lightning. 100,000 x 257 byte long messages are received from a private queue in 30 seconds.

My multithreaded app takes 10 seconds to read 10 messages from 10 transactional queues.

The CPU usage of my app is 99!!!

The core of my thread code follows...





HANDLE hQueue = A Valid Queue Handle - I used MQOpenQueue to open queue the same way the MSDN example at the bottom does it.

char pMessage[4096]; this is a buffer big enough to handle MSMQ messages.

s_msmq_message *in_mess is a structure of the message;

int thisListener is a unique integer [0 to 9] identifying this thread;

int volatile is_continue; This is 1 while my app is running and 0 when the user hits the close button.

HRESULT hr = S_OK;


HANDLE mutexThreadListeners is a global mutex used to sync calls to HandleDataMessage.

DLG is a global pointer to my main dialog. ie. DLG = this;




while(is_continue)

memset(pMessage, 0, sizeof(pMessage));
hr = mq.ReceiveTransactionalMessage(hQueue, pMessage, sizeof(pMessage)); //mq - my MSMQ wrapper
if(hr != S_OK)
{
in_mess = (s_msmq_message*)pMessage;

wait_status = WaitForSingleObject(mutexThreadListeners, INFINITE);

//HandleDataMessage(in_mess, thisListener);

iRecordCount++;

iTotalMessages += 1;

// **** sprintf(strRecordCount, "Processed %d Records", DLG->iTotalMessages);

// **** DLG->m_labelRecordCount.SetWindowText(strRecordCount);

ReleaseMutex(mutexThreadListeners);

}

if(hr == MQ_ERROR_IO_TIMEOUT)
{
TRACE1("\n%sMessage Queue Empty.", strQueueArray[thisListener]);
}

SwitchToThread();

}







What else is really wierd - when I remove the comments from the lines marked with ****, some of my threads wont close. I call WaitForMultipleObjects(10, hThreadListeners, TRUE, INFINITE) in OnClose and my program hangs. If I set WaitForMultipleObjects to time out I get all sorts of nasty access violations.

If I remove these lines, my application closes down like a dream, but it still hogs the CPU!!!




How can I stop these threads from hogging CPU time? And why do the lines marked with **** cause my app not to close properly?




The MSMQ code I use to receive and open queues can be found at...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msmq/msmq_using_reading_msg_6feh.asp[^]




I modified the function to receive a queue handle as a parameter - so I don't open and close the queue for each message.



Please Help, Thanks in advance.
GeneralRe: Threads using up too much CPU Pin
the one dono15-May-05 6:20
the one dono15-May-05 6:20 
QuestionQuestion: How to retrieve the HINSTANCE when you have HWND? Pin
lxcid14-May-05 23:50
lxcid14-May-05 23:50 
AnswerRe: Question: How to retrieve the HINSTANCE when you have HWND? Pin
bharadwajgangadhar15-May-05 2:05
bharadwajgangadhar15-May-05 2:05 
AnswerRe: Question: How to retrieve the HINSTANCE when you have HWND? Pin
PJ Arends15-May-05 10:42
professionalPJ Arends15-May-05 10:42 
GeneralVisual C++ Callbacks Issue - Auto Callbacks Pin
Axonn Echysttas14-May-05 23:08
Axonn Echysttas14-May-05 23:08 
GeneralRe: Visual C++ Callbacks Issue - Auto Callbacks Pin
the one dono15-May-05 4:47
the one dono15-May-05 4:47 
GeneralRe: Visual C++ Callbacks Issue - Auto Callbacks Pin
Axonn Echysttas15-May-05 5:47
Axonn Echysttas15-May-05 5:47 
GeneralRe: Visual C++ Callbacks Issue - Auto Callbacks Pin
the one dono15-May-05 6:34
the one dono15-May-05 6:34 
GeneralRe: Visual C++ Callbacks Issue - Auto Callbacks Pin
Axonn Echysttas15-May-05 11:59
Axonn Echysttas15-May-05 11:59 
GeneralRe: Visual C++ Callbacks Issue - Auto Callbacks Pin
ThatsAlok15-May-05 18:27
ThatsAlok15-May-05 18:27 
GeneralRe: Visual C++ Callbacks Issue - Auto Callbacks Pin
Axonn Echysttas16-May-05 2:08
Axonn Echysttas16-May-05 2:08 
QuestionGetting WM_DROPFILES from child control? Pin
matthew18014-May-05 19:26
matthew18014-May-05 19:26 
GeneralAddFontResource Pin
Inov14-May-05 16:52
Inov14-May-05 16:52 
GeneralRe: AddFontResource Pin
Jack Puppy14-May-05 17:38
Jack Puppy14-May-05 17:38 
Generaldialog box Pin
rain71114-May-05 14:57
rain71114-May-05 14:57 
GeneralRe: dialog box Pin
David Crow15-May-05 16:28
David Crow15-May-05 16:28 
GeneralRe: dialog box Pin
rain71122-May-05 3:47
rain71122-May-05 3:47 

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.