Can SwitchToThread function be used to yield to other processes in the system? I have a dll that does processor-intensive work (the CPU slaves at 100% for several minutes at a time). I can afford a little delay at the cost of CPU utilization. Any idea whether this would work? Any other ideas?
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.

Yes, you can use this function.
The main execution entities in NT (i believe you're using NT) are threads. Processes are groups of threads with certain shared attributes (like process address space), but in terms of kernel time scheduler all threads are the same with cumulative priority taken from thread itself and its process.

So if you yield to the other threads it will let them execute.

The other thing to consider is that really time-critical threads have already been given higher priority and
THEY will have processor time when they need (or a little later ;).

So if you want constrain your application of CPU resource, that isn't enough.
Consider putting sleep call for a few milliseconds in the main cycle if you have one, or similar means.

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
I think your best bet is to use SetThreadPriorityBoost() and/or  SetThreadPriority().  so that your thread gets less CPU time when other threads are in need of it.  The best thing about this sort of approach is that the thread still gets lots of CPU time when it is available.
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

From novice to tech pro — start learning today.