Presentation is loading. Please wait.

Presentation is loading. Please wait.

Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CS 547/490 Network.

Similar presentations


Presentation on theme: "Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CS 547/490 Network."— Presentation transcript:

1 Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu CS 547/490 Network Programming Semaphore and Shared Memory IPC2.PPT/001

2 CS 547/490 Network Programming What is a problem in “pipe”? Not flexible - only FIFO queue is implemented FIFO Other Data Structures Stack Tree Heap Binary-Tree B-Tree List Table Link-List IPC2.PPT/002

3 CS 547/490 Network Programming What is a problem in “pipe” (continued)? Not flexible - only FIFO queue is implemented A solution: Semaphore + Shared Memory = similar to pipe, but almost any data structure can be implemented by “semaphore + shared memory” IPC2.PPT/003

4 CS 547/490 Network Programming Shared Memory: Shared memory is a piece of memory space that does not belong to any particular user process. Shared memory can be accessed (shared) by multiple processes. Shared memory is created by OS. Two processes can send and receive data through shared memory No limitation in the order data is accessed (and even bi-directional) Race condition is there (users are responsible for avoiding race condition) IPC2.PPT/004

5 CS 547/490 Network Programming OS Allocate/Manage Shared Memory WRITE READ Process 2 Process 1 Can access any address within a shared memory Property of Shared Memory (1) “Random Access” is possible IPC2.PPT/005 Not FIFO any more

6 CS 547/490 Network Programming OS Allocate/Manage Shared Memory READ WRITE Process 2 Process 1 Property of Shared Memory (2) No limitation in “direction” WRITE READ IPC2.PPT/006

7 CS 547/490 Network Programming OS Shared Memory Process 2 Process 1 READ WRITE READ OS does NOT provide protection against race-condition Property of Shared Memory (3) No protection from “Race Condition” IPC2.PPT/007

8 Time Server OS CS 547/490 Network Programming Application Example Writer Process Time Keeper (Delta Time) Client 1 Client 2 Client n Remote Client 1 Remote Client 2 Remote Client n Shared Memory 12:59:59 IPC2.PPT/008

9 CS 547/490 Network Programming (1) Multiple readers can simultaneously access to the clock (2) When the time keeper (= writer) updates the time, no client can access (3) Once the time keeper leaves, multiple clients can access to the clock Access Rules to the Shared Memory IPC2.PPT/009

10 CS 547/490 Network Programming START Writer? accept create shared memory folk Time Keeper YES folk Client NO IPC2.PPT/010

11 CS 547/490 Network Programming IPC2.PPT/011 Time Keeper (Writer) Time Client (Reader) reader_count = reader_count +1; if (reader_count = 1) wait (writer); wait (mutex); signal (mutex); reader_count = reader_count -1; if (reader_count = 0) signal (writer); wait (mutex); signal (mutex); wait (writer); signal (writer); The Time Keeper Updates the current time A reader reads the current time writer, mutex = binary (mutual exclusion) semaphore


Download ppt "Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CS 547/490 Network."

Similar presentations


Ads by Google