Inside Windows 8: Pedro Teixeira - Thread pools

Sign in to queue

Description

Continuing with our series of conversations with engineers in Windows, we meet Pedro Teixeira, a software developer on the Windows kernel team (aka core OS) who has improved the Windows thread pools in Windows 8. Thread pools are thread management subsystems (user mode and kernel mode) where threads are created and queued for any number of arbitrary tasks (work) required by applications and services. As it turns out, there are some significant improvements to the thread pool pattern in Windows 8. Pedro takes the time necessary - at the whiteboard for the entire interview - to dig into the details, beginning with first principles. So, if you don't really know what a thread pool is, then you will after the first 5 minutes of this interview. As the conversation progresses, the complexity will increase, but will remain suitable for most user mode application developers. Speaking of user mode, much of the time in this interview is spent on the Windows 8 user mode thread pool. The kernel mode thread pool is addressed towards the end of the conversation.

In Windows 8, there is a new thread pool model and new thread creation policy. What is the new policy? How is the new user mode thread pool designed? How is it better than its predecessors? What does this all mean for developers?

Tune in. Learn. Huge thanks to Pedro for taking the time to dig in - and for explain things in such a clear way.

Embed

Download

Download this episode

The Discussion

  • User profile image
    McHalls

    Hmm maybe this new threadppol policy is the reason why latest Firefox is dead slow, but also many application startup time grew from <1sec to 3-4 seconds since the Win7->Win8 upgrade Expressionless

    Anyway, really nice to see so much passion on an interesting topic, thank you! Smiley

  • User profile image
    felix9

    Good.

    Thread pool is my working horse for everything not in the UI. I use QueueUserWorkItem to do async work, RegisterWaitForSingleObject to do notification/timeout/timer, and I use it to do (overlapped) IO too, I wish I can use BindIoCompleionRoutine to do IO but that dont have a async timeout notification as far as I can see, so I use RegisterWaitForSingleObject with the event in OVERLAPPED instead, which works, but its kinda wierd that BindIoCompletionRoutine has such a flaw, and I wonder if using RegisterWaitForSingleObject for IO completion has any performance hit, since its TP_WAIT while BindIoCompletionRoutine uses TP_IO ? on the other hand I wish there is RegisterWaitForMultipleObjects which would be super useful.

  • User profile image
    pmsjt

    Felix9, note that all the APIs you have listed are actually quite dated. The Win32 API has gone through significant changes in Vista which make it easier to develop by orders of magnitude (given it has built-in reference count, support for synchronization and cancelation). Please refer to this link: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686766(v=vs.85).aspx.

  • User profile image
    pmsjt

    McHalls, You seem to be describing a pervasive impact on all applications startup. ThreadPool has been tested thoroughly not to affect any such generic scenario. In fact, the loader remains mostly single-threaded to this day. There are multiple factors that could be influencing your results, such as storage drivers. Also note that Win8 does come with Defender complemented by Security Essentials anti-malware, where Win7 did not. Smart screening is also turned on by default validating the binaries being loaded are not back-listed as malware. A delicate balance with "secure by default".

  • User profile image
    OmariO

    Very very interesting.

    But what about conventional .NET thread pool in .NET 4.5 (on Win 8 but not Win RT apps)? Is it based on this new OS thread pool?

  • User profile image
    felix9

    @pmsjt: Thank you, I never really looked into those shiny new APIs because, well, I need to target XP, and in a foreseeable future, so the first thing I do with a new C++ project is setting _WIN32_WINNT to 0x0501. Expressionless

    But actually, async timeout notification is useless in XP anyway since there is no CancelIoEx, and CancelIo can only be called in the same thread that started it. Sad So I kinda understand why MS teams all left XP support behind, because XP stinks. but I'm not Microsoft so I still have to.

    Now I still want to ask, if I use those new Vista APIs, can I start a socket (TCP/UDP) overlapped io and let the threadpool notify me if its not yet completed after a timeout ?? I mean, I know maybe I CAN do that, but maybe I need both ...Wait APIs and ...Io APIs, and set 2 callbacks, but IMHO thats too much for such a common task, can I get the notification with just ...Io APIs ?

  • User profile image
    oskark

    Really interesting stuff. @Charles, will you be looking into the internals and implementation of the RIO http://bit.ly/t14OoV sockets.

  • User profile image
    br1

    Best c9 show yet.  The complexity level was just right.

  • User profile image
    deiruch

    Thanks for the great video. Enjoyed it!

  • User profile image
    Denzil

    Excellent! More like this please.

     

  • User profile image
    C64

    Very good interview! Thanks both Pedro and Charles.

    One thing I'm curious is what development tools you guys in the kernel world use.

    We in the user mode world use Visual Studio with its convenience and facilities; but when you are writing code for the kernel, what are your tools? What editors do you use? What debuggers? Is there a special build of the C compiler for kernel mode, or do you use our classical "user mode" cl.exe?

    A video on "development tools for kernel mode devs" would be interesting.

    Thanks.

     

  • User profile image
    Manuel Filipe Vilhena

    Great presentation! Congratulations for all Pedro.

  • User profile image
    Andrew Sha

    It was mentioned that a full blown thread pool (as opposed to work items handled by ExQueueWorkItem) is implemented in the Win8 kernel – is API exposed/ documented?

  • User profile image
    RyanRies

    Fantastic video.  I agree that the complexity level was just right; enough to be educational, but not too pedantic.  I very much appreciate it.

  • User profile image
    Pedro Lamas

    Awesome presentation, Pedro! Congratulations!!

    Ou como diríamos por terras de Portugal, Parabéns! Wink

Add Your 2 Cents