COMP 3000 2012 Week 10 Notes: Difference between revisions
formatting |
more formatting |
||
Line 5: | Line 5: | ||
** multi processes | ** multi processes | ||
** multi hosts | ** multi hosts | ||
**Kernel tasks/ handlers | ** Kernel tasks/ handlers | ||
Mutual exclusion | Mutual exclusion | ||
*"Take turns" | * "Take turns" | ||
HOw? | HOw? | ||
Line 19: | Line 19: | ||
** Between the if statment and the assignment, the CPU may schedule anothe rprocedure that accesses variable m. | ** Between the if statment and the assignment, the CPU may schedule anothe rprocedure that accesses variable m. | ||
Concerning | Concerning the lab: | ||
* Each echo (line) is atomic. | |||
* Flock controls access to writing to race.txt | |||
* Flock tries to write to lock, but if it can't, it'll wait | |||
Starvation | Starvation | ||
* There's an issue with writing and reading locks | |||
* If a process depends on a lock and that lock is never freed, that process will starve | |||
Deadlock | Deadlock |
Revision as of 17:27, 8 November 2012
Concurrency
- Examples:
- multi threaded
- multi processes
- multi hosts
- Kernel tasks/ handlers
Mutual exclusion
- "Take turns"
HOw?
- State "variable". Stores state saying who's turn is it? COudl be memory location, variable, file on disk
- These include locks, semaphores, mutexes, monitors
- Variables: set a variable to true or false if a current facility is being used. THis is a stupid method though, because two procedures may write to that variable at the same time
- "TOCTTOU" Time to check to time to use:
- if ( m < 1) then m = 1;
- Between the if statment and the assignment, the CPU may schedule anothe rprocedure that accesses variable m.
Concerning the lab:
- Each echo (line) is atomic.
- Flock controls access to writing to race.txt
- Flock tries to write to lock, but if it can't, it'll wait
Starvation
- There's an issue with writing and reading locks
- If a process depends on a lock and that lock is never freed, that process will starve
Deadlock
- "Death Pact"
- Mutually dependent on resources
- see wikipage
- happens when there are multiple locks
- requirements for deadlock:
- mutual exclusion
- hold + wait.
- no preemption. "Sit there, waiting for that lock forever"
- circular wait "I'm waiting on you you and you're waiting on me"
- How do deal with deadlock?
- 1. Ignore it! Ostrich algorithm
- 2. detection. Are we in deadlock?
- Example: Timeout. If a process times out, then it's depending on resources that
aren't there.
- Watchdog timer. "If you don't call me every 30 minutes, call the cops!!!"
- check state every interval, react if something isn't right
- Watchdog timer. "If you don't call me every 30 minutes, call the cops!!!"
- 3. Prevention. Make sure that one of the one of the requirements for deadlock is never satisfied
- 4. Avoidance. Requirements are satisfied... So watch the transactions to see if
anything fishy happens. If so, pull out. (banker's algorithm):w
Semaphores
- just a counting variable
Mutex
- semaphore with values of either 1 or 0
- mutual exclusion
- flock is a file based mutext