> Hi
In multicore or multiprocessor systems, thread scheduler can work on every
processor at the same time. Right?
Why does it matter?
Is there a global thread queue that CPUs look up to select a thread or
also thread database (or queue) is per processor as well?
Why does it matter?
If it is per processor my question is, if I build a simple MFC dialog
window and run it, why don’t I see the same number of window equal to my
CPU’s core number. Because every core can select to run the thread that
runs UI.
I have no idea what you mean by “the same number of window equal to my
CPU’s core number.” Windows are not associated with CPUs, they are
associated with threads, and consider the following scenario: you have an
EN_CHANGE notification for your edit control. You have no idea from
keystroke to keystroke which core will be executing the code. The
scheduler will schedule the thread, and which core it schedules it to is
undefined, as far as you are concerned.
Any thread can normally run on any core, and unless you have established a
preferred processor or set thread affinity, you don’t control it, you
don’t know it, and most important, YOU DON’T CARE!
There is only one thread for the entire GUI.
Other question is,so, If I create a thread, do I always protect it with
mutex to not be able to be run concurrently by other cores?
It is considered Poor Practice to ever have a secondary thread that has
user-visible controls. Those of us who have C++/MFC in our MFC
recognition would never, ever do this, and we know what can go wrong; we
just don’t want to have to deal with the problems. Essentially, you do
ALL your UI interactions from the main thread of your MFC app. You do not
pop up dialogs or message boxes in a secondary thread, ever. You do not
touch any window of your UI from a secondary thread, ever. If you think
you need to do any of these things (a) you are wrong (b) you will get into
trouble and (c) there is always a way to avoid doing this. I’ve been
programming in MFC for about 15 years, and I have never needed to ASK any
of the questions you have asked, because I have made sure that the answers
never MATTERED. If you think the answer matters, your design is probably
wrong.
You do not “protect threads”, and anything you hear related to such a
concept is nonsense. The purpose of locks is to protect DATA. Threads do
not need “protection”, and I have no idea what it would mean if they did.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer