1 / 13

HW/Study Guide

HW/Study Guide. Synchronization. Make sure you understand the HW pro blems!. global shared int counter = 0, BUFFER_SIZE = 10 ; Producer: while (1) { while (counter == BUFFER_SIZE) ; // do nothing buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; counter++;

padma
Télécharger la présentation

HW/Study Guide

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HW/Study Guide

  2. Synchronization • Make sure you understand the HW problems!

  3. global shared int counter = 0, BUFFER_SIZE = 10 ; Producer: while (1) { while (counter == BUFFER_SIZE); // do nothing buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; counter++; }

  4. Consumer: while (1) { while (counter == 0); // do nothing nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; counter--; // consume the item }

  5. Identify the race condition in this version of the consumer/producer problem. • Fix this race condition using the TestAndSet hardware instruction. • Now assume there is still one producer but there are now two consumers. • Does this introduce any additional race conditions (the correct answer is yes!)?

  6. If so, where does it occur? • Now fix this additional race condition using a semaphore.

  7. Assume I have just learned about using semaphores to synchronize the order in which certain statements are executed. • I think this is really cool, and want to give it a try. So I want to use semaphores to enforce the following execution order: • Statement S1 of process P1 executes before statement S2 of process P2. • Statement S2 of process P2 executes before statement S3 of Process P3.

  8. Statement S3 of process P3 executes before Statement S1 of process P1. • Use semaphores to enforce this ordering, or, show how this may not be such a great idea (i.e., what is the problem here?).

  9. Now assume we have four processes and want Statement S1 in P1 to execute before statement S2 in P2 before S3 in P3. Also, we want Statement S4 in P4 to execute after S2 in P2. • Use semaphores to enforce this ordering. You must explicitly initialize any semaphores you use.

  10. Assume there is one producer process and one consumer process, and that they share a buffer with 10 slots. • Implement the producer/consumer problem using semaphores. You must explicitly initialize the semaphores that you use.

  11. Paging • Assume a 16-bit virtual address space with pages that are 2048 bytes. How many pages are in the logical address space? • Consider the following page table for some process in this system. 0 2 1 3 21

  12. 0 2 1 3 21 Paging • Consider the following page table for some process in this system, and assume the logical address is 2052. To what physical address will this logical address be mapped? Show the steps you took to determine this address.

  13. What is the Translation Lookaside buffer? • What purpose does it serve? • Consider a 64-bit address space with 4K pages. How many pages are there in this virtual address space? • Is this a big number? • You will most likely be asked to work through a two-level page table example.

More Related