VB6: Multithreading and Multiple Core CPU

Hi!

For some time now I've been working on implementing multiple threads on VB6 with a standard EXE.  I think I got it working right now, so I'm trying to get a little more performance out of my app.  I've noticed that both threads (only two right now) run on the same core, or at least it seems that way in the Performance tab of Task Manager.  Is there a way (API?) to control which core runs which thread?  Maybe this could be applied to a system with multiple CPUs too, but I'm not sure.

Thanks!
TCV
LVL 6
TaconvinoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bpmurrayCommented:
What you're looking for is a way to create a SMP app using VB. I doubt very much that you're going to be able to do that. While compilers are now available for C and C++ that can optimize for multiple processors (as you mentioned, this is exactly what multi-core processors are), doing this in VB in its current form is pretty difficult. Search around for articles and books on Parallel Computing for more information on this stuff.
0
TaconvinoAuthor Commented:
Yeah, I think a compiler solution makes sense.  I wasn't really expecting it could be done, considering how old VB6 core is... I'll just leave this question hanging for a while to see if someone can come up with a hack or something.  It has happened before!  :-)

Thanks!
TCV
0
3_SCommented:
I'm not familiar with using threads in VB6, but I put the complete program on to another cpu

There also a setthreadaffinitymask
So you could look into the api's getCurrentThread and SetThreadAffinityMask but for that you are on your own. I can't help you with that


Public Declare Function GetCurrentProcess Lib "kernel32.dll" () As Long
Public Declare Function SetProcessAffinityMask Lib "kernel32.dll" (ByVal hProcess As Long, ByVal dwProcessAffinityMask As Long) As Long
 
'*-*-*-*-*-*-
 
Call SetProcessAffinityMask(GetCurrentProcess(), &H1)  'complete program runs on cpu 1  
or
Call SetProcessAffinityMask(GetCurrentProcess(), &H2)  'complete runs on cpu 2

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TaconvinoAuthor Commented:
Sounds promising.  The thing is it applies to processes, not threads.  But that got me thinking: could there be a SetThreadAffinityMask?  And yes, there is one!  Reading about this function made me realize that maybe to "hand assign" a thread to run on a specific processor may not be as good as I thought.  From the MSDN article:

"Setting an affinity mask for a process or thread can result in threads receiving less processor time, as the system is restricted from running the threads on certain processors. In most cases, it is better to let the system select an available processor."

Not that good.  But there's yet another function, called SetThreadIdealProcessor.  The thing is, for what I can tell, I might as well let the OS choose the "ideal processor" for me instead of using this API.  So the thing is, I don't think it's such a good idea to hand-pick the processor after all.

This can still be open for discussion a little bit more, just in case.

Thanks!
TCV
0
TaconvinoAuthor Commented:
OK, so there may be a way to do it, but it is hardly a solution for what I need.  This was a mistake from my part, and anyway, the information provided was excelent.

Thanks!
TCV
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.