Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results


More Info on Driver Writing and Debugging

The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.

Check out The OSR Learning Library at:

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

Setting thread affinity

parsaparsa Member Posts: 46

Hi All,

I am creating some number of threads based on the system processor count for doing repeating task such as file encryption. In this case do I need to set affinity for the threads so that each thread can run on each available processor instead of all of them contending for the same processor. Or I should leave it for the OS to take care the processor allotment for the threads?

Any idea or input greatly appreciated.



  • anton_bassovanton_bassov Member MODERATED Posts: 5,245

    Or I should leave it for the OS to take care the processor allotment for the threads?

    Unless you have some VERY specific situation (like, for example, an embedded system with all running software known in advance), this is, indeed, the right way to go.....

    Anton Bassov

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,916

    As a general rule, setting thread affinity at all is almost always a bad idea. The net effect is merely to reduce the number of opportunities your code has to execute. The Windows scheduler is very, very good, and had been highly tuned over the last three decades.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • MBond2MBond2 Member Posts: 304

    The general rule here is that if you don't know what affinity to set, than don't set any affinity at all. The OS usually does a very good job but there are exceptions. and you intrigue me by saying file encryption. is this a hypothetical workload or something that you are actually trying to do?

    depending on the implementation, this sort of workload can be in the hard category - where it is alternately IO and CPU bound. and good implementations will use many pending IRPs and queues of buffers but much depends on your exact requirements

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Developing Minifilters 24 May 2021 Live, Online
Writing WDF Drivers 14 June 2021 Live, Online
Internals & Software Drivers 2 August 2021 Live, Online
Kernel Debugging 27 Sept 2021 Live, Online