Lab6-sync2

Lab6-sync2 - Lab 6 Synchronization II POSIX Semaphore 1...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab 6 Synchronization II POSIX Semaphore 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Before You Start Login to Linux Boot the PC, and select the option: SLIM/SWIM Choose 5 Ubuntu 10.04 Login the system using CS account info
Background image of page 2
Outline In last workshop, you have learnt Mutex In this workshop, you will learn POSIX Semaphore Solution for Readers-Writers Problem
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
POSIX Semaphores All POSIX semaphore functions and types are prototyped or defined in semaphore.h Two types of semaphores Named semaphores Provide synchronization between unrelated process and related process as well as between threads. As the semaphore is named, processes simply “open” the semaphore and use it. Unnamed semaphores Useful for sharing between multiple threads or shared-memory processes Must be placed in a region of shared memory
Background image of page 4
Unnamed Semaphores A semaphore is represented with the data structure sem_t Preparation for creating the semaphores Threads None Just declare the semaphore(s) under the global scope Processes Create a shared memory region IPC shared memory Using mmap()
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Creating and Opening a Semaphore int sem_init (sem_t *sem , int pshared , unsigned int value ); sem points to a semaphore object to initialize pshared argument indicates whether the semaphore is local to the current process ( pshared is zero ) or is to be shared between several processes ( pshared is not zero).
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/01/2010 for the course CS 2342 taught by Professor Dr during the Spring '10 term at HKU.

Page1 / 17

Lab6-sync2 - Lab 6 Synchronization II POSIX Semaphore 1...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online