MTH 4355 Semaphores

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/18

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:15 PM on 4/30/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

19 Terms

1
New cards

semaphore

a synchronization primitive that acts as both a lock and condition variable

2
New cards

semaphore code

sem_init(pointer to semaphore object, shared between threads, condition variable)


sem_wait(semaphore s)

decrements the condition variable

if negative, puts thread to sleep


sem_signal(semaphore s)

increments the condition variable by 1

and wakes up a thread if any waiting


3
New cards

Reader/Writer Locks

single writer, multiple readers

Assume first thread is writer

Can only write when no readers in critical section

(lock for updating reader count, and lock for writing)

4
New cards

Dining philosipher

to avoid circle wait, have one thread grab a lock in a different order than the rest

5
New cards

atomicity violation

two threads access a shared variable at the same time

6
New cards

atomicity violation solution

add a lock

7
New cards

order violation

T2 assume T1 has created something T2 requires, but T1 did not create yet

8
New cards

order violation solution

add condition variables

9
New cards

encapsulation

why deadlock occurs most often

10
New cards

mutual exclusion, hold-and-wait, no preemption, circular wait

4 conditions required for a dead lock

11
New cards

prevent circular wait

give a total ordering for grabbing locks

12
New cards

prevent hold-and-wait

add more locks and make sure you obtain all locks at once

13
New cards

prevent no preemption

trylock

14
New cards

livelock

awkward moment when you trylock but its released after they tried, so another thread grabs lock


can add random delay to fix

15
New cards

prevent mutual exclusion

use hardware no lock method

16
New cards

deadlock prevention via scheduling

include meta data about locks, and schedule in a way that no deadlock can occur

17
New cards

deadlock prevention with detector

detect a deadlock, reboot OR break lock cycles(but loose some data in process)

18
New cards

no preemption

resources cannot be forcibly removed from threads holding them

19
New cards

hold-and-wait

thread holds onto resources while waiting for additional resources