7 Matching Annotations
  1. Last 7 days
    1. With the continued growth of multicore processing, applications containing hundreds—or even thousands—of threads are looming on the horizon. Designing such applications is not a trivial undertaking: programmers must address not only the challenges

      Implicit threading is defined by what the programmer no longer has to do: instead of manually creating and managing individual threads, the developer only identifies tasks, units of work that could run in parallel, and hands responsibility for turning those tasks into actual threads over to a library or runtime, typically using the many-to-many model under the hood.

    2. The one-to-one model (Figure 4.8) maps each user thread to a kernel thread. It provides more concurrency than the many-to-one model by allowing another thread to run when a thread makes a blocking system call. It also allows multiple threads to run in parallel on multiprocessors. The only drawback to this model is that creating a user thread requires creating the corresponding kernel thread, and a large number of kernel threads may burden the performance of a system. Linux, along with the family of Windows operating systems, implement the one-to-one model.

      both Windows and Linux threads are described there as one-to-one, which this section sets up as the reason. It is worth connecting the drawback mentioned here, kernel-thread creation overhead, back to the economy benefit claimed in Section 4.1, since the one-to-one model is the one case where creating a thread does still involve a real kernel-level allocation and not just a lightweight user-space operation.

    3. The many-to-one model (Figure 4.7) maps many user-level threads to one kernel thread. Thread management is done by the thread library in user space, so it is efficient (we discuss thread libraries in Section 4.4). However, the entire process will block if a thread makes a blocking system call. Also, because only one thread can access the kernel at a time, multiple threads are unable to run in parallel on multicore systems. Green threads—a thread library available for Solaris systems and adopted in early versions of Java—used the many-to-one model. However, very few systems continue to use the model because of its inability to take advantage of multiple processing cores, which have now become standard on most computer system

      The many-to-one model is a good illustration of a design that made sense historically but became obsolete for a structural reason rather than an implementation flaw. It was fast precisely because thread operations stayed in user space and avoided system calls, but that same design choice is what makes it impossible to ever run two threads on two cores simultaneously, since the kernel only ever sees one thread

    4. One interesting fact about Amdahl's Law is that as N approaches infinity, the speedup converges to 1/S. For example, if 50 percent of an application is performed serially, the maximum speedup is 2.0 times, regardless of the number of processing cores we add. This is the fundamental principle behind Amdahl's Law: the serial portion of an application can have a disproportionate effect on the performance we gain by adding additional computing co

      This connects back to the five challenges from the previous passage, specifically "balance" and "data dependency." Amdahl's Law is really the mathematical consequence of failing to eliminate serial dependencies: every dependency you leave unresolved between tasks effectively becomes part of S, and this passage shows that even a plateau as low as 50 percent serial caps you at 2x no matter how many cores exist, which is a strong argument for why identifying and removing dependencies matters more than simply adding hardware.

    5. An application typically is implemented as a separate process with several threads of control. Below we highlight a few examples of multithreaded applications: An application that creates photo thumbnails from a collection of images may use a separate thread to generate a thumbnail from each separate image. A web browser might have one thread display images or text while another thread retrieves data from the network. A word processor may have a thread for displaying graphics, another thread for responding to keystrokes from the user, and a third thread for performing spelling and grammar checking in the background.

      These three examples are useful because they show three different reasons to thread something: the thumbnail case is about parallelizing identical work across images, the browser case is about keeping the interface responsive while I/O happens, and the word processor case is about running a genuinely background task, spell check, without the user noticing it at all.

    6. Amdahl's Law is a formula that identifies potential performance gains from adding additional computing cores to an application that has both serial (nonparallel) and parallel components. If S is the portion of the application that must be performed serially on a system with N processing cores, the formula appears as follows: speedup≤1S+(1−S)

      Working through the numbers makes the formula concrete: with S = 0.25 and N = 2, the denominator is 0.25 + 0.75/2 = 0.625, and 1/0.625 = 1.6, matching the book's claim. This shows how even a modest serial fraction caps your gains hard, doubling the cores from two to four only got the speedup from 1.6 to 2.28, not close to doubling, because that fixed 25 percent serial chunk never gets any faster no matter how many cores you throw at it.

    7. A thread is a basic unit of CPU utilization; it comprises a thread ID, a program counter (PC), a register set, and a stack. It shares with other threads belonging to the same process its code section, data section, and other operating-system resources, such as open files and signals. A traditional process has a single thread of control. If a process has multiple threads of control, it can perform more than one task at a time. Figure 4.1 illustrates the difference between a traditional single-threaded process and a multithreaded process

      a thread carries its own control-flow state, meaning ID, program counter, registers, and stack, but shares everything else, code, data, and open files, with the other threads in its process. That sharing is what makes threads so much cheaper to create than processes, a point the chapter returns to explicitly under "Economy" a page later.