Click here to Skip to main content
15,921,203 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Want to start VC++ Pin
Nishad S7-Apr-06 1:30
Nishad S7-Apr-06 1:30 
AnswerRe: Want to start VC++ Pin
Ștefan-Mihai MOGA7-Apr-06 3:23
professionalȘtefan-Mihai MOGA7-Apr-06 3:23 
QuestionStrange include Pin
Monty26-Apr-06 21:21
Monty26-Apr-06 21:21 
AnswerRe: Strange include Pin
toxcct6-Apr-06 22:24
toxcct6-Apr-06 22:24 
Questionthread problem Pin
ramanujachari6-Apr-06 20:52
ramanujachari6-Apr-06 20:52 
AnswerRe: thread problem Pin
Naveen6-Apr-06 20:58
Naveen6-Apr-06 20:58 
GeneralRe: thread problem Pin
Mike O'Neill7-Apr-06 17:04
Mike O'Neill7-Apr-06 17:04 
AnswerRe: thread problem Pin
Matt Godbolt6-Apr-06 21:04
Matt Godbolt6-Apr-06 21:04 
Threads, like any other process, will take up as much CPU as there is available. If you're doing pure processing in a separate thread, there's not a lot you can do - you can reduce the priority of the thread but this will only reduce the CPU time if other processes are running too.

I suspect more likely you're writing code like:
void MyThread()
{
    // Wait for a message
    extern volatile bool isThereAMessage;
    while (!isThereAMesage) { /* do nothing */ }
    ...process message...
}

This type of behaviour, spinning in a loop waiting for something to happen, is a frequent cause of threads taking up all available CPU time. If you are in this kind of situation, then I suggest you look at your OS's thread synchronisation and wait functions. If you're on windows, WaitForMultipleObjects, WaitEvent and similar. These put your thread to sleep until a message (or timeout) occurs, releasing the CPU for other processes to use it.

[NB the code example I have above is it itself not strictly thread safe; instead of using pure volatile bools, one should use thread safe calls, for example the Win32 InterlockedIncrement() and InterlockedAdd() etc]

Matt Godbolt
Engineer, ProFactor Software
StyleManager project
GeneralRe: thread problem Pin
includeh106-Apr-06 21:16
includeh106-Apr-06 21:16 
GeneralRe: thread problem Pin
Matt Godbolt7-Apr-06 4:37
Matt Godbolt7-Apr-06 4:37 
GeneralRe: thread problem Pin
Stephen Hewitt7-Apr-06 2:53
Stephen Hewitt7-Apr-06 2:53 
GeneralRe: thread problem Pin
Blake Miller7-Apr-06 4:08
Blake Miller7-Apr-06 4:08 
GeneralRe: thread problem Pin
Stephen Hewitt8-Apr-06 1:58
Stephen Hewitt8-Apr-06 1:58 
GeneralRe: thread problem Pin
Matt Godbolt7-Apr-06 4:33
Matt Godbolt7-Apr-06 4:33 
AnswerRe: thread problem Pin
Aqueel6-Apr-06 21:19
Aqueel6-Apr-06 21:19 
Questionaccess and deleting of ListBox items Pin
parichaybp6-Apr-06 20:46
parichaybp6-Apr-06 20:46 
AnswerRe: access and deleting of ListBox items Pin
Hamid_RT6-Apr-06 20:50
Hamid_RT6-Apr-06 20:50 
GeneralRe: access and deleting of ListBox items Pin
parichaybp6-Apr-06 21:00
parichaybp6-Apr-06 21:00 
AnswerRe: access and deleting of ListBox items Pin
Naveen6-Apr-06 20:57
Naveen6-Apr-06 20:57 
GeneralRe: access and deleting of ListBox items Pin
parichaybp6-Apr-06 21:13
parichaybp6-Apr-06 21:13 
AnswerRe: access and deleting of ListBox items Pin
Hamid_RT6-Apr-06 21:16
Hamid_RT6-Apr-06 21:16 
QuestionDiff between C Structure and C++ Structure Pin
Krishnatv6-Apr-06 20:40
Krishnatv6-Apr-06 20:40 
AnswerRe: Diff between C Structure and C++ Structure Pin
Matt Godbolt6-Apr-06 20:57
Matt Godbolt6-Apr-06 20:57 
GeneralRe: Diff between C Structure and C++ Structure Pin
Cedric Moonen6-Apr-06 21:04
Cedric Moonen6-Apr-06 21:04 
AnswerRe: Diff between C Structure and C++ Structure Pin
includeh106-Apr-06 20:59
includeh106-Apr-06 20:59 

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.