|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
is there a "process affinity" switchHi All,
Please forgive my ignorance on this issue. I need my program to only run on one processor (for some reason, Hyperthread screws up my text writes). In a previous post, a kind person showed me the code to set my "process affinity." Before I go and have this coded into the program, I wanted to make sure there was no switch in the compiler that would essentially do the same thing. Many thanks, --Tony > Please forgive my ignorance on this issue. Not in VB6, have a look at the SetProcessAffinityMask() API call:> > I need my program to only run on one processor (for some > reason, Hyperthread screws up my text writes). > > In a previous post, a kind person showed me the > code to set my "process affinity." Before I go and have > this coded into the program, I wanted to make sure there > was no switch in the compiler that would essentially do > the same thing. '*** Private Declare Function GetCurrentProcess Lib "Kernel32.dll" () As Long Private Declare Function SetProcessAffinityMask lib "Kernel32.dll" ( _ ByVal hProcess As Long, ByVal dwProcessAffinityMask As Long) As Long .... ' Only use the first processor Call SetProcessAffinityMask(GetCurrentProcess(), &H1) '*** There's a little more in this old thread on the subject: http://groups.google.co.uk/group/microsoft.public.vb.winapi/msg/83e88190612c4212 Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ Mike D Sutton wrote:
Show quoteHide quote > Not in VB6, have a look at the SetProcessAffinityMask() API call: Thank you! Love examples! :-)> > '*** > Private Declare Function GetCurrentProcess Lib "Kernel32.dll" () As Long > Private Declare Function SetProcessAffinityMask lib "Kernel32.dll" ( _ > ByVal hProcess As Long, ByVal dwProcessAffinityMask As Long) As Long > > ... > > ' Only use the first processor > Call SetProcessAffinityMask(GetCurrentProcess(), &H1) > '*** > > There's a little more in this old thread on the subject: > http://groups.google.co.uk/group/microsoft.public.vb.winapi/msg/83e88190612c4212 > Hope this helps, > > Mike > > > - Microsoft Visual Basic MVP - > E-Mail: ED***@mvps.org > WWW: Http://EDais.mvps.org/ > > --Tony
Show quote
Hide quote
"Tony" <T***@invalid.com> wrote in message Since VB6 came out long before Hyperthreading, I doubt you'll find a news:dj0oqi$ft9$2@domitilla.aioe.org... > Hi All, > > Please forgive my ignorance on this issue. > > I need my program to only run on one processor (for some > reason, Hyperthread screws up my text writes). > > In a previous post, a kind person showed me the > code to set my "process affinity." Before I go and have > this coded into the program, I wanted to make sure there > was no switch in the compiler that would essentially do > the same thing. > > Many thanks, > --Tony compiler switch. All compiler options are shown by clicking 'Project/<your project name> Properties/Compile' -- Ken Halter - MS-MVP-VB - http://www.vbsight.com DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Please keep all discussions in the groups..
Show quote
Hide quote
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message However, since VB 6 came out after the advent of multi-processor systems,news:utpSHk10FHA.3256@TK2MSFTNGP09.phx.gbl... > "Tony" <T***@invalid.com> wrote in message > news:dj0oqi$ft9$2@domitilla.aioe.org... > > Hi All, > > > > Please forgive my ignorance on this issue. > > > > I need my program to only run on one processor (for some > > reason, Hyperthread screws up my text writes). > > > > In a previous post, a kind person showed me the > > code to set my "process affinity." Before I go and have > > this coded into the program, I wanted to make sure there > > was no switch in the compiler that would essentially do > > the same thing. > > > > Many thanks, > > --Tony > > Since VB6 came out long before Hyperthreading, I doubt you'll find a > compiler switch. All compiler options are shown by clicking 'Project/<your > project name> Properties/Compile' > this isn't a valid case against such a switch. The issue is simply that VB 6, at it's heart, is single threaded and was never designed for multi-processing. Even ActiveX controls are internally single threaded. The COM subsystem in Windows is what allows them to appear to be multi-threaded. This is also one of the sources of numerous posts I've seen over the years that run along the lines of "I've subclassed my form, but the IDE keeps crashing when I'm debugging them." Mike Sutton's solution will work on Windows 2000, but it may fail on XP and Server 2003. The difference is that W2K treats HT enabled processors as if they are seperate processors while XP and later are HT aware and somtimes treats them as a single processor. When true multi-core processors start arriving en-masse later this year and next year, the problem will get even worse. OP - please post your code that is having the problems. I suspect the real solution would be to create a Critical Section around your file writes. This way only a single thread could write to the file at a time. If, as I suspect, the writes are coming from two seperate processes, the Critical Thread section will requre the use of a system wide semaphore, making it a little more difficult, but not too much so. Mike Ober. Show quoteHide quote > -- > Ken Halter - MS-MVP-VB - http://www.vbsight.com > DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm > Please keep all discussions in the groups.. > > > > OP - please post your code that is having the problems. I suspect the real Hi Mike,> solution would be to create a Critical Section around your file writes. > This way only a single thread could write to the file at a time. If, as I > suspect, the writes are coming from two seperate processes, the Critical > Thread section will requre the use of a system wide semaphore, making it a > little more difficult, but not too much so. > > Mike Ober. I am having (WinAPI) flushes added to each (WinAPI) WriteFile statement. I am also going to add the other Mike's SetProcessAffinityMask statement at the beginning of the program. It will be a couple of weeks before I get results back. If Happy Camping is not achieved, I will repost the section of code that writes to the text file. I appreciate your help and comments. Many thanks, --Tony > Mike Sutton's solution will work on Windows 2000, but it may fail on XP and If hyperthreading is not enabled in the BIOS then Windows will see a single processor (and treat it as a single> Server 2003. The difference is that W2K treats HT enabled processors as if > they are seperate processors while XP and later are HT aware and somtimes > treats them as a single processor. processor), however as long as it's enabled then the OS should see two processors. I've tested and verified this on 3 machines running XP or Server 2003 as AFAIK hyperthreading is not supported in Win2K. Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ In W2K, hyperthreaded CPUs are reported as distinct CPUs. The OS itself
doesn't know that they are actually a single HT enabled CPU. The problem is that the SetAffinityMask API doesn't know either. There is an additional API that deals with HT and multi-core CPUs. Mike Ober. "Mike D Sutton" <ED***@mvps.org> wrote in message single processor (and treat it as a singlenews:uhUAGaB1FHA.2072@TK2MSFTNGP14.phx.gbl... > > Mike Sutton's solution will work on Windows 2000, but it may fail on XP and > > Server 2003. The difference is that W2K treats HT enabled processors as if > > they are seperate processors while XP and later are HT aware and somtimes > > treats them as a single processor. > > If hyperthreading is not enabled in the BIOS then Windows will see a > processor), however as long as it's enabled then the OS should see two processors. I've tested and verified this on 3> machines running XP or Server 2003 as AFAIK hyperthreading is not supported in Win2K.Show quoteHide quote > Hope this helps, > > Mike > > > - Microsoft Visual Basic MVP - > E-Mail: ED***@mvps.org > WWW: Http://EDais.mvps.org/ > > > |
|||||||||||||||||||||||