Some Thread Internals

So far, I’ve explained how to implement a thread function and how to have the system create a thread to execute that function. In this section, we’ll look at how the system pulls this off.

Figure 6-1 shows what the system must do to create and initialize a thread.

How a thread is created and initialized

Figure 6-1. How a thread is created and initialized

Let’s look closely at this figure to understand exactly what’s going on. A call to CreateThread causes the system to create a thread kernel object. This object has an initial usage count of 2. (The thread kernel object is not destroyed until the thread stops running and the handle returned from CreateThread is closed.) ...

Get Windows® via C/C++, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.