Click here to Skip to main content
16,014,591 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Alpha in GDI Pin
Iain Clarke, Warrior Programmer13-Sep-04 3:41
Iain Clarke, Warrior Programmer13-Sep-04 3:41 
GeneralRe: Alpha in GDI Pin
Joel Holdsworth13-Sep-04 7:39
Joel Holdsworth13-Sep-04 7:39 
GeneralReplicating an instance in a multi-threaded app Pin
0v3rloader11-Sep-04 8:56
0v3rloader11-Sep-04 8:56 
GeneralRe: Replicating an instance in a multi-threaded app Pin
Gary R. Wheeler12-Sep-04 2:58
Gary R. Wheeler12-Sep-04 2:58 
GeneralRe: Replicating an instance in a multi-threaded app Pin
0v3rloader12-Sep-04 5:48
0v3rloader12-Sep-04 5:48 
GeneralUsing a critical section in a high priority thread Pin
Chris Hills11-Sep-04 5:28
Chris Hills11-Sep-04 5:28 
GeneralRe: Using a critical section in a high priority thread Pin
Baris Kurtlutepe11-Sep-04 8:33
Baris Kurtlutepe11-Sep-04 8:33 
GeneralRe: Using a critical section in a high priority thread Pin
Andrew Walker12-Sep-04 14:37
Andrew Walker12-Sep-04 14:37 
This is a fairly serious design issue. Windows is not a real time operating system, so you can't rely on it to do the right thing with regard to scheduling of threads in this way. The scenario you are describing with the thread being kicked off the CPU and struggling to get back on is 'priority inversion'.

Understanding the windows threading model is difficult, and it takes time. One of the simplest ways to think of it is that the main thread (what I believe is your 'normal' thread) does nothing but handle the message pump (event queue). Messages in the main thread are dealt with in two ways, synchronously (PostMessage) or asynchronously (SendMessage). PostMessage forces events to be dealt with immediately, SendMessage buffers the messages in a queue to be dealt with in FIFO order.

The main thread can only do one thing at a time, however it can be interrupted by another thread. If the main thread enters a critical section it prevents another thread from entering that region at the same time, until the main thread leaves the critical section. AFAIK another event having occured (a WM_TIMER message) is irrelevant because the timer message is buffered in the message pump.

Like the last poster recommended, I suggest that you don't bother changing thread priorities unless you can show that this provides a significant benefit at the end of the day - 'premature optimisation is the root of all evil'. It may be that with a single thread at priority 24 the main thread won't get any CPU or enough CPU to run the GUI.

2) rely upon the operating system doing something reasonable at a low level - like giving non-blocked threads a chance on the CPU in preference to blocked threads. This sounds like you are worried about 'deadlocks' but they generally occur only in situations where multiple resources are in contention.

Chris Hills wrote:
3) Will all 32-bit versions of Windows behave in the same way with regard to this possible problem?
Yes, although apparently their are kernels now available which sit on top of Windows that minimise this problem, but they are fairly expensive, and probably not redistributable. If you do need an operating system which can avoid this problem look at something like MaRTE[^]

Also, ensure that the frequency of WM_TIMER messages on the main thread occurs at the rate that you expect it too, especially with the priority of the main thread so high. From past experience WM_TIMER messages can only be set to arrive at a minimum of 10ms intervals, and even then I've seen that regularly blow out to 200ms. It may be more appropriate to poll the clock from the main thread and interpolate volumes between key-points.


If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.

Rudyard Kipling

GeneralRe: Using a critical section in a high priority thread Pin
Blake Miller13-Sep-04 6:17
Blake Miller13-Sep-04 6:17 
GeneralRe: Using a critical section in a high priority thread Pin
Andrew Walker13-Sep-04 12:58
Andrew Walker13-Sep-04 12:58 
GeneralVC++6 WinXP - Find Dialog and SerializeRaw don't work Pin
Kwakas11-Sep-04 4:49
Kwakas11-Sep-04 4:49 
GeneralMulti select list control Pin
Tyrus18211-Sep-04 4:17
Tyrus18211-Sep-04 4:17 
GeneralRe: Multi select list control Pin
Gary R. Wheeler12-Sep-04 3:02
Gary R. Wheeler12-Sep-04 3:02 
QuestionHow to issue the mouse_event without "SendInput" Pin
Member 244207211-Sep-04 3:50
Member 244207211-Sep-04 3:50 
GeneralMultiple document templates Pin
Jens Christiansen11-Sep-04 3:10
Jens Christiansen11-Sep-04 3:10 
Generalcalculating response time for a http request Pin
emmatty11-Sep-04 0:36
emmatty11-Sep-04 0:36 
GeneralRe: calculating response time for a http request Pin
Alexander M.,12-Sep-04 4:28
Alexander M.,12-Sep-04 4:28 
Generallist control selection Pin
Tyrus18210-Sep-04 18:51
Tyrus18210-Sep-04 18:51 
GeneralRe: list control selection Pin
Branislav11-Sep-04 4:05
Branislav11-Sep-04 4:05 
GeneralRe: list control selection Pin
Tyrus18211-Sep-04 4:20
Tyrus18211-Sep-04 4:20 
GeneralRe: list control selection Pin
Branislav11-Sep-04 5:04
Branislav11-Sep-04 5:04 
GeneralRe: list control selection Pin
Ravi Bhavnani11-Sep-04 5:07
professionalRavi Bhavnani11-Sep-04 5:07 
GeneralADO MySQL query problem Pin
Graham Holdaway10-Sep-04 16:34
Graham Holdaway10-Sep-04 16:34 
GeneralRe: ADO MySQL query problem Pin
Arsalan Malik10-Sep-04 20:23
Arsalan Malik10-Sep-04 20:23 
GeneralRe: ADO MySQL query problem Pin
Anonymous11-Sep-04 18:51
Anonymous11-Sep-04 18:51 

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.