Operating System: Three Easy Pieces --- Why It Gets Worse: Shared Data (Note)

The simple thread example we showed above was useful in showing how threads are

created and how they can run in different orders depending on how the scheduler decides

to run them. What it doesn‘t show you, though, is how threads interact when they access

shared data.

          The Heart Of The Problem: Uncontrolled Scheduling

To understand why this happens, we must understand the code sequence that the compiler

generates for the update to counter. In this case, we wish to simple add a number 1 to counter.

Thus, the code sequence for doing so might look something like this (in X86);

mov 0x8049a1c, %eax

add $0x01, %eax

mov %eax, 0x8049a1c

This example assumes that the variable counter is located at address 0x8049a1c. In this

three-instruction sequence, the x86 mov instruction is used first to get the memory value at

the address and put it into register eax. Then, the add is performed, adding 1 to the contents

of the eax register, and finally, the contents of eax are stored back into memory at the same

address.

时间: 2024-08-05 18:14:10

Operating System: Three Easy Pieces --- Why It Gets Worse: Shared Data (Note)的相关文章

Operating System: Three Easy Pieces --- Mechanism: Limited Direct Execution (Note)

In order to virtualize the CPU, the operating system needs to somehow share the physical CPU among many jobs  running seemingly at the same time. The basic idea is simple: run one process for a little while, then run another, and so forth. By time sh

Operating System: Three Easy Pieces --- Process (Note)

1. How can the operating system provide the illusion of a nearly-endless supply of said CPUs? The OS creates this illusion by virtualizing the CPU. The basic technique, known as the time- sharing the CPU, allows users to run as many concurrent proces

Operating System: Three Easy Pieces --- Locks: Pthread Locks (Note)

The name that the POSIX library uses for a lock is mutex, as it is used to provide mutual exclusion between threads, i.e., if one thread is in the critical sections, it excludes the others from entering until it has completed the section. Thus, when

Operating System: Three Easy Pieces --- Limited Directed Execution (Note)

In order to virtualize the CPU, the operating system needs to somehow share the physical CPU among many jobs running seemingly at the same time. The basic idea is simple: run one process for a little while, then run another one, and so forth. By time

Operating System: Three Easy Pieces --- Beyond Physical Memory: Mechanisms (Note)

Thus far, we have assumed that an address space is unrealistically small and fits into the physical memory. In fact, we have been assuming that every address space of ervery running process fits into memory. We will now relax these big assumptions, a

Operating System: Three Easy Pieces --- Thread API (Note)

This chapter briefly covers the main properties of the thread API. Each part will be explained further in the subsequent chapters, as we know how to use the API. More details can be found in various books and online sources. We should note that the s

Operating System: Three Easy Pieces --- Page Fault (Note)

Recall that with TLB misses, we have two types of systems: Hardware managed TLBs (where the hardware looks in the page table to find the desired translation) and software managed TLBs ( where the OS does). In either type of systems, if a page is not

Operating System: Three Easy Pieces --- API (Note)

Aside: RTFM --- Read The Man Pages Many times in this book, when referring to a particular system call or library call, we will tell you to read the mannual pages, or man pages for short. Man pages are the original form of documantation that exist on

Operating System: Three Easy Pieces --- Locks: Test and Set (Note)

Because disabling interrupts does not work on multiple processors, system designers started to invent hardware support for locking. The earliest multiprocessor systems, such as the Burroughts B5000 in the  early 1960's, had such support; today all sy