rec11-2010 - ● Decrement: sem_wait Semaphores ● How...

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

View Full Document Right Arrow Icon
Today Assignment 4 Questions? Condition Variables (Quick Review) Semaphores Exercise – busy-wait vs. CV vs. Semaphores
Background image of page 1

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

View Full DocumentRight Arrow Icon
Condition Variables What are condition variables? When should we use them? Describe the following functions in your own words: pthread_cond_wait(cv,mutex) pthread_cond_signal(cv) pthread_cond_broadcast(cv)
Background image of page 2
Semaphores Semaphores are another synchronization method other than mutex locking. Think of a semaphore as a special kind of integer: It can be incremented or decremented atomically. If the value of the semaphore is 0, it cannot be decremented. Threads that try to decrement it when its value is 0 go to sleep. Increment: sem_post (like “signal”)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ● Decrement: sem_wait Semaphores ● How many threads can access the “critical section” of code below? sem_t accesslock; sem_init(&access_lock, 0, 2); // thread code: sem_wait(&access_lock); // critical section sem_post(&access_lock); Exercise ● Synchronize our program that uses two threads to print out alternating “+-+-+-”. One thread prints out “+”, the other “-”. ● We have already implemented this for busy-waiting for you. Run this code to see how badly it performs. (Timers included in code) ● Use two new methods to synchronize this program and compare their performance with busy-wait: condition vars, semaphores...
View Full Document

This note was uploaded on 10/21/2011 for the course CSCI 4061 taught by Professor Tripathi during the Spring '08 term at Minnesota.

Page1 / 5

rec11-2010 - ● Decrement: sem_wait Semaphores ● How...

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

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