Preview

Process Synchronization

Satisfactory Essays
Open Document
Open Document
778 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Process Synchronization
Chapter 6: Process Synchronization

Module 6: Process Synchronization
 Background  The Critical-Section Problem  Peterson’s Solution  Synchronization Hardware  Semaphores  Classic Problems of Synchronization  Monitors  Synchronization Examples  Atomic Transactions

Operating System Concepts

6.2

Silberschatz, Galvin and Gagne ©2005

Background
 Concurrent access to shared data may result in data

inconsistency
 Maintaining data consistency requires mechanisms to

ensure the orderly execution of cooperating processes
 Suppose that we wanted to provide a solution to the

consumer-producer problem that fills all the buffers. We can do so by having an integer count that keeps track of the number of full buffers. Initially, count is set to 0. It is incremented by the producer after it produces a new buffer and is decremented by the consumer after it consumes a buffer.

Operating System Concepts

6.3

Silberschatz, Galvin and Gagne ©2005

Producer while (true) /* produce an item and put in nextProduced while (count == BUFFER_SIZE) ; // do nothing buffer [in] = nextProduced; in = (in + 1) % BUFFER_SIZE; count++; }

Operating System Concepts

6.4

Silberschatz, Galvin and Gagne ©2005

Consumer while (1) { while (count == 0) ; // do nothing nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--; /* consume the item in nextConsumed }

Operating System Concepts

6.5

Silberschatz, Galvin and Gagne ©2005

Race Condition


count++ could be implemented as register1 = count register1 = register1 + 1 count = register1 count-- could be implemented as register2 = count register2 = register2 - 1 count = register2 Consider this execution interleaving with “count = 5” initially:





S0: producer execute register1 = count {register1 = 5} S1: producer execute register1 = register1 + 1 {register1 = 6} S2: consumer execute register2 = count {register2 = 5} S3: consumer execute register2 = register2 - 1

You May Also Find These Documents Helpful

  • Powerful Essays

    CODE FOR THE ABOVE FRAGMENT addi $t6, $zero, 101 # the loop termination value add $t0, $zero, $zero # i = 0 addi $t2, $a0, 0 # ptr to current A[i] addi $t3, $a1, 0 # ptr to current B[i] loop: lw $t4, 0($t3) # load B[i] add $t4, $t4, $s0 # B[i] + c sw $t4, 0($t2) # store in A[i] addi $t0, $t0, 1 # i++ addi $t2, $t2, 4 # ptr to next A[i] addi $t3, $t3, 4 # ptr to next B[i] bne $t0, $t6, loop # if i < 101, goto loop IF ANY QUERIES REGARDING CODE…

    • 107 Words
    • 1 Page
    Powerful Essays
  • Powerful Essays

    POW 9 IMP3

    • 1192 Words
    • 5 Pages

    Create 2 formulas, one that will calculate the last number in terms of the first number and a constant increase in rate as well as the total amount of numbers. The second formula will add ass of the resulting numbers from the first formula together after the last number is calculated.…

    • 1192 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    Nt1310 Unit 1 Study Guide

    • 378 Words
    • 2 Pages

    If the multithreading scheme replicates all of the software-visible state, including privileged control registers and TLBs, then it enables _________ to be created for each thread.…

    • 378 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Hog Problem

    • 370 Words
    • 2 Pages

    If the schedule is run without interruption then the plant will begin its day with 4000 hogs in inventory ready for slaughter in increments of 1000 hogs every hog. The hog inventory at the plant will continue to rise every hour until noon when it will hit its highest peak. After noon the hog numbers will continue to decrease until the end of daily slaughtering which is 5 pm. At that time shipments of hogs will continue to arrive until receiving closure at midnight.…

    • 370 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    printf(" %d \t\t %d\n\n",stfor->wt,stfor->tt); ttl_wt += stfor->wt; ttl_tt += stfor->tt; temp = np = stfor; del_node(np,1) ; ++i; } else { stfor->bt -= qt; stfor->tt = temp->tt + qt; printf(" %d \t\t %d\n\n",stfor->wt,stfor->tt); np = temp = stfor; del_node(np,2); ins_node(temp); } }while(stfor !=…

    • 401 Words
    • 2 Pages
    Better Essays
  • Good Essays

    Investigations of Buffers

    • 991 Words
    • 4 Pages

    We also had to calculate the grams of salt needed to make Buffer B. The salt we used was ammonium chloride (NH4Cl). The calculation below shows how we found the appropriate weight.…

    • 991 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Bio Lab

    • 629 Words
    • 3 Pages

    A buffer is a set of chemicals that can keep the pH of a stable by alternately donating and accepting ions that contribute to pH. An example of this is carbon dioxide.…

    • 629 Words
    • 3 Pages
    Good Essays
  • Good Essays

    9. Use one pipet to pick up 25 mL of the Barium Chloride solution and the other to pick up 25 mL of…

    • 1224 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    4 15 15

    • 320 Words
    • 2 Pages

    1. Explain what is in a buffer. Discuss the function of a buffer. How will pH change when small amounts of acids or bases are added to the buffer solution?…

    • 320 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    OPS/571 week 4

    • 402 Words
    • 2 Pages

    Now, suppose that there are currently 64 pumps in inventory and there are customer orders that have been committed and must be filled. These inputs result in the following table.…

    • 402 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Enzyme Lab

    • 1094 Words
    • 5 Pages

    Repeat steps 3 and 4, increasing the substrate by 1 mL and decreasing the buffer by 1 mL, keeping the total volume at 6ml. Do this until you reach 6mL of substrate and 0mL of buffer. (See data table)…

    • 1094 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    06

    • 4188 Words
    • 33 Pages

    When a positive value is assigned to the INCREMENT BY clause of the CREATE SEQUENCE command, numeric values are generated in descending order.…

    • 4188 Words
    • 33 Pages
    Satisfactory Essays
  • Good Essays

    Buffer A and buffer B were prepared first with the concentration of Buffer A being roughly half that of Buffer B. The preparation of Buffer A is as follows: 100 mL of 0.75 M NaAc solution, 100 mL of 0.22 M HAc…

    • 757 Words
    • 4 Pages
    Good Essays
  • Better Essays

    Ph and Buffers Lab

    • 1819 Words
    • 8 Pages

    The third experiment we conducted was to test the buffer zone of a buffer solution. We used a 2 pH buffer solution and steadily added hydrochloric acid, then sodium hydroxide as a base. Our hypothesis was that we would reach…

    • 1819 Words
    • 8 Pages
    Better Essays
  • Good Essays

    Ncc Case

    • 1281 Words
    • 6 Pages

    2. What is the maximum long-term achievable throughput rate of receiving Plant 1? What factors affect this throughput rate?…

    • 1281 Words
    • 6 Pages
    Good Essays

Related Topics