2 threads on dual processor machine


I use 2 threads (CWinThread class) in a vs app running on a dual 
processor (Xeon) machine.

Does anone tell me how I can make each thread run on separate processor. 
The compiler doesn't seem to do it automaticaly.


eberlems (1)
8/31/2003 6:08:45 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 35


This is almost never the right thing to do -- doing so, you will rip the
S right out of SMP.

That said, use the API function SetThreadAffinityMask.  The mask that
you pass in a bit vector of the processors that the thread is allowed to
run on.  It is easy to construct if you *KNOW* that there will always be
at least two processors - but the safer approach would be to discover
how many processors there are with a call to the API function

When calling SetThreadAffinityMask, make sure that there has not been a
call to SetProcessAffinityMask - (or at the very least, make sure that
the bit mask in the SetThreadAffinityMask is a subset of the mask that
you get in the GetProcessAffinityMask call)

The bits in the process affinity mask have precedence over the bits in
the thread mask (if a processor is not available to the process,  that
processor can not be scheduled for a time slice for any thread in that

Additionally, if you want to take a softer approach, have a look at the
API function SetThreadIdealProcessor.

roy fine

"Markus Eberlein" <eberlems@iis.fhg.de> wrote in message
> Hello,
> I use 2 threads (CWinThread class) in a vs app running on a dual
> processor (Xeon) machine.
> Does anone tell me how I can make each thread run on separate
> The compiler doesn't seem to do it automaticaly.
> thank's
> Yannick

rlfine5330 (47)
8/31/2003 8:09:24 PM
Because you are assuming that they WILL be able to run concurrently. Note, however, that
there are dozens of threads in the system which you have no control over, such as all the
file system threads. So if you have two threads, A and B, if they CAN run concurrently,
they will, and if they can't, it is because there is something more important to run. By
forcing processor dependencies, thread B can be held up a very long time while higher
priority (often kernel) threads preempt processor 1, so the thread is completely blocked,
while processor 0 is sitting idle! It is impossible for you to control the scheduling, or
the number of threads not part of your process, or the number of threads that run in
super-high-priority in the kernel, so any attempt you make to force concurrency by tricks
like processor affinity will simply constrain the thread to run less efficiently. Bottom
line: this approach is doomed. The system will schedule as much concurrency as is
possible; anything you attempt will limit its choices. The more limited its choices are,
the worse your overall throughput will be.

One thing we learned years ago about multiprocessor scheduling (I worked on a 16-processor
system in 1975-1977): every attempt on the part of the user to assign threads to
processors uniformly resulted in worse performance than if the scheduler is permitted to
handle the issue itself.

Your assumption is that forcing processor affinity will result it better concurrency. It
won't. It will result in worse overall performance in nearly every case that can occur,
because you will limit the amount of time the scheduler will be able to run it. 
On Tue, 2 Sep 2003 09:15:39 -0500, "Kanon Wood" <Kanonw@yahoo.com> wrote:

>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>> Hint:  you haven't the foggiest idea if it is going to benefit you.
>Maybe we're looking at different assumptions, so I'll get those out of the
>Two worker threads with completely separate tasks (no synchronization
>between them) both report to a single GUI thread via messaging.
>Why would running these threads on different processors _not_ benefit?

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
newcomer (15972)
9/3/2003 3:27:18 AM

Similar Artilces:

Major help needed!!!! #2
Thanks for the post GE, I was able to find another computer with exce 97 still loaded. I opened the existing spreadheet and went through th tools options and unchecked th 1904 date option. Went back to m updated computer and the dates came across just fine. Also thanks Don, your comment will be noted. I was in a rushed an panic'd state : -- KyDean ----------------------------------------------------------------------- KyDeano's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1556 View this thread: http://www.excelforum.com/showthread.php?threadid=27128 ...

error 0x800ccc13 #2
I have Outlook 2000 installed on WinXP home. After installing modem software (for fax purposes) I now receive error 0x800ccc13 when performing 'send receive' in Outlook. Outlook Express now also fails with 0x800ccc0f error. I've disabled all spywatch and filtering software and tested Winsock using Netdiag and Winsock passes but there is a fail for NetBT transports test failed (I'm assuming because I removed all services other than TCP/IP.) I've reinstalled Outlook Express using the procedure from #318378 http://support.microsoft.com/default.aspx?scid=kb;en-us;318378&...

MS Publisher #2
Does anyone know how to open an MS Publisher 2000 document with MS Publisher 97? You cannot open a Publisher 2000 document in Publisher 97. You need the same or later version of Publisher to open Publisher documents. -- Why is it that people don't realize that they will probably have a problem opening a newer file with an older program? Rarely does that ever happen. "Riobard" <morgan.riobard@sivh.ie> wrote in message news:12b801c38ceb$868aea80$a401280a@phx.gbl... > Does anyone know how to open an MS Publisher 2000 document > with MS Publisher 97? Because t...

Help ! #2
Hi, I have developed an application in VC++ where spelling of a word will be checked in Excel (English is default). I have used Automation for this. I want to use the same application for German and French languages. Could someone help me on how to select the language programmatically so that selected language's dictionary will be activated and spelling of a word will be checked in that selected language's dictionary? TIA, Gary ...

Error adding users #2
Hello all: I am working with a new installation of MSCRM, and when I try to add a user I get the "AN error ahs occurred, please contact your system administrator" message. So I enabled tracing, and I have pasted the error details from the trace file below... Does anyone have any ideas? John. >MSCRM Application Error Report: -------------------------------------------------------------------------------------------------------- Error: Index was out of range. Must be non-negative and less than the size of the collection. >Parameter name: index Error Message: Index was ou...

RMS 2.0 Manual
I have a general question. I remember over year ago when we were buying RMS license we were receivig license+box with manual, user guide and Instalation CD. From some time whenever we order new license there is A2 cartboard "envelope" comming which have another A3 soft envelope in it and eventually this one ontains 10cm x 10cm RMS license sheet. Can someoe tell me is it just us or everybody have it this way. Before after we did training for customer he had Manual/User Guide to look back into if he forgot about something, I know that this manual is exact printout of ...

Qty sold/Qty available #2
Any way of doing this on a top performer report? I would like to see the qty sold and qty available per item, not individual sales. THANKS! CT >-----Original Message----- >CT, > >Detailed Sales Report and add the On Hand column. (right click on the >report, Show/Hide Columns) > >-- >Jeff > >Get Secure! - www.microsoft.com/security > >===================================================== > >When responding to posts, please "Reply to Group" via >your newsreader so that others may learn and benefit >from your issue. > >=======...

FTP #2
Greetings. I have an MFC application working just fine using ftp with CInternetSession and CFtpConnection, and I'm using windows ftp server. this app needs to check file's size and dates where CFtpFileFind seems to works perfectly. I have some doubts: 1. this app seems to work fine with filezila ftp server... is there somethig I have to know working with other ftp servers specially servers runing on linux? I have seen that list files is not standard... 2. MFC can handle FTPS?? if not, does any one knows a good library? I'm starting to see libcurl. Any suggestions are welc...

Button for goal seek?! #2
Hello I have the following data: 5 6 12 15 20 Total of all those added I will have to set a goal seek button so that i can put the total i want and then change the cell i want i tried using a macro but i couldnt do it... I just want to do it using a click of a button instead of going to menu>goal seek>etc etc Thanks a lot From John -- Neo1 ------------------------------------------------------------------------ Neo1's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=30329 View this thread: http://www.excelforum.com/showthread.php?threadid=515571 Any ...

2 cells 2 colors
Hi All, Here's my glitch: I've got 2 dropdown/combo boxes in a user form. Both offer variou color options. The 1st one colors an active cell the correct color tha is chosen. The 2nd dropdown colors the cell directly to the right or th active cell in the same manner. My code is pretty crude & not ver efficient, but it works correctly. The problem is when color 2 is no chosen. Currently, if a color isn't chosen, I can put an "X" in th cell, or color it a certain color, but what I want is to color i whatever the color of the active cell is. Any ideas? Thanks -- S...

Outlook 2007
WinXP Pro SP3 Outlook 2007 - Pop3 Can outlook 2007 have mail stores (PST) greater than 2 GB? I have a friend who keeps all for his business and is pushing the limit. I was told that Outlook 2007 raised the limit. Any clarification is appreciated. -- ***************** John Lenz JohnLenz@comcast.net 20Gb + if using the new, default, pst file type of Unicode which is the default in Outlook 2003 and later If however you upgraded outlook from a pre 2003 version, then it maybe that you are still using the old outlook format data file which has the size limitation. Within Outlook, select ...

Forms.dic #2
Hi, I might have missed out something. After installing MGP v8.0 SP5 on the workstation, I then I clicked on Modifier, the system created a file called forms.dic. After this, I can't open certain forms like Sales Transaction Windows, Sales Order Fulfillment, Inventory Transaction, etc. Other forms like Item Class ID, Journal Entry are fine. Anything I miss out here? TIA, Sugih Were these forms modified? Is security pointing to the modified forms? The new forms.dic will be empty and not contain these forms. Most firms either copy a complete forms.dic from a working workstation ...

Office 97 to 2003: Excel: enter data w/fixed 2 decimal. 2000. be. #2
When I enter number "2000." I get 20.00 - yes, set decimals at 2 but earlier excel would accept change if you entered decimal with number. this is slowing down a budget prep and I'd sure like some help - online and tutorials say "enter decimal" but this is not working. what am I doing wrong? ...

One Control for 2 codes
My Combo Box cbGSTOptions selects either tax or no tax but after making my selection I need to update with another control form the calculation to work Control 2 is under the line==== Can I incorporate these two code to just the Afterupdate of my Combo Box ---------------------------------------------------------------------- Option Compare Database Option Explicit Dim recInvoice_ItMdt As ADODB.Recordset Dim recInvoice As ADODB.Recordset, dblGSTContentsValue As Double, lngIntermediateID As Long Dim dblGSTOptionsValue As Double Dim bModify As Boolean Dim ynCheque As Boolean, ln...

matrix item in rms 2.0
When creating a matrix item in 2.0, and selecting the option to show the dimensions of the size and color with the description, I get a error message that "itemlookup code or item description exeeds the allowed length. do you wish to continue truncating the lookup code or description." However with the old version I was able to do this. Is the description field more restricted in size? Also it whould be easier to be able to enter the matrix reorder #,minimum order & case quantity when you create a matrx item, for now i have to do it with the wizard. Does anybody know ...

2 X 2 Splitter Windows #2
What is wrong with the following code? I am trying to create a 2 X 2 splitter window. It should look like this. CMyTreeView | CMyListView __________________|___________________ | CPictureView | CDetailView It compiles correctly but when I run it I get an error in the WinSplit routine of MFC. if(!m_wndSplitterWnd1.CreateStatic(this,1,2)) return FALSE; if(!m_wndSplitterWnd1.CreateView(0,0, RUNTIME_CLASS(CMyTreeView), CSize(0,0), pContext)) return FALSE; if(!m_wndSplitterWnd2.CreateStatic(&m_wn...

Exchange 2007 Beta 2 question
Hi I have the mailbox, CA, hub and UM on one server. I am trying to create a new email life cycle policy, but the option to do this cannot be found. I right click on the mailbox icon in EMC under "organization" but the option is not listed. The only listed options are. Also the tab in ESM for this is not there New address list New managed custom folder new managed fodler mailbox policy new offline address list On Wed, 23 Aug 2006 13:58:02 -0700, skip <skip@discussions.microsoft.com> wrote: >Hi > >I have the mailbox, CA, hub and UM on one server. I am trying to...

CRM 1.2 subnet change
I am moving my CRM servers to a different site for DR, and I need to know if I need to do anything to the server besides updating the DNS records with the new IPs. Anyone have any experience with this? Thanks ...

AutoCorrect #2
Can 'AutoCorrect' listings be transported from an old computer to a new one? I have hundreds of 'auto-corrections' that would take me all day to redo. Copying the dictionary does not seem to do it. Robert, it is stored as a .ACL file ,do a search for *.acl and copy it to the new computer -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 97 & 2000 ** remove news from my email address to reply by email ** "robert gerald" <...

duplicate #2
I have spreadsheet that contains about 200,000 records. Many of them are duplicated. How can I sort them out so that I can only have one of each? Metalteck wrote: || I have spreadsheet that contains about 200,000 records. Many of them || are duplicated. How can I sort them out so that I can only have one || of each? have a look here: http://www.cpearson.com/excel/duplicat.htm#HighlightingDuplicates -- Gordon Burgess-Parker Interim Systems and Management Accounting www.gbpcomputing.co.uk ASAP Utilities has a feature that does this nicely.......... Free at www.asap-utilities.com Vaya...

RMS version 1.2 Database not connecting on register 2
I have a RMS system using version 1.2 that I purchased used. I have been successful in setting up the datebase and getting my date imported from my old system. The system has a total of 3 computers, 2 for registers and then a file server. I have POS1/register 1 computer working fine. My problem is with Register 2. I can access the administration program on register 2 computer and assign the database. I can also use manager and see my list of items in the database. My problem comes when I try to launch store operations. There is a delay and then I get an error message that says &...

Random Number Generator #2
I need to create a random number generator in Excel 2000 to fill one column and about 3000 rows. How do I go about doing this? To generate a random whole number between 1 and 3000, you can use =int(rand()*(3000-1)+1) binder Wrote: > I need to create a random number generator in Excel 2000 to fill on > column > and about 3000 rows. How do I go about doing this -- BenjieLo ----------------------------------------------------------------------- BenjieLop's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1101 View this thread: http://www.excelforum.co...

Calendars #2
Schedule of Events is visible but not avtive on a Calendar. How do you make of use of a schedule and activate it in a Calendar. ...

Find Function #2
hello to all I have the following: AGUA LUN I 101 ANTOFAGASTA 1568 JOSE CODOCEO ALBERT 155 MEJILLONES 18420 JUAN ZEPEDA ALCATRAZ 81 MEJILLONES 1310 VICTOR ESCOBAR ALDEA II 364 MEJILLONES 900066 RAMON GARCIA ANFIBIO 383 MEJILLONES 901225 JOSE CORTES ANWAR 210 TOCOPILLA 18363 PEDRO ANTIQUERA AOD 972 ANTOFAGASTA 25698 JUAN COZ APOCALIPSIS 215 TALTAL 1057 JUAN TORRES AQUA MAN II 1261 ANTOFAGASTA 914428 JORGE FLORES I need find the first position numeric. I use the following funcion HALLAR({"1"\"2"\"3"\"4"\"5"\"6"\"7"\"8...

Large (5 1/2 x 8 1/2) postcards on Publisher 2003
I can't figure out how to create 2 postcards instead of 4 on 8 1/2 x 11 paper. Each postcard needs to be 1/2 of the page. Page setup, custom, type 8.5 width, 5.5 height, portrait. Publisher will say it will print two copies per sheet. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "pjraser" <pjraser@discussions.microsoft.com> wrote in message news:FB43381E-B0AE-455D-8CF3-AF0EF542DCFB@microsoft.com... >I can't figure out how to create 2 postcards instead of 4 on 8 1/2 x 11 > paper. Each postcard need...