COMP 3000 2012 Week 10 Notes: Difference between revisions

From Soma-notes
Cdelahou (talk | contribs)
added initial notes
 
Cdelahou (talk | contribs)
formatting
Line 1: Line 1:


Concurrency
Concurrency
  Examples:
*Examples:
  - multi threaded
** multi threaded
  - multi processes
** multi processes
  - multi hosts
** multi hosts
  - Kernel tasks/ handlers
**Kernel tasks/ handlers


Mutual exclusion
Mutual exclusion
  "Take turns"
*"Take turns"


HOw?  
HOw?  
* State "variable". Stores state saying who's turn is it? COudl be memory location,
* State "variable". Stores state saying who's turn is it? COudl be memory location, variable, file on disk
variable, file on disk
* These include locks, semaphores, mutexes, monitors
* These include locks, semaphores, mutexes, monitors


* Variables: set a variable to true or false if a current facility is being used.  
* 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
  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:
* "TOCTTOU" Time to check to time to use:
** if ( m < 1) then m = 1;  
** if ( m < 1) then m = 1;  
** Between the if statment and the assignment, the CPU may schedule anothe rprocedure that accesses
** Between the if statment and the assignment, the CPU may schedule anothe rprocedure that accesses variable m.
    variable m. Your c


Concerning assignement:
Concerning assignement:
Line 30: Line 26:
Starvation
Starvation
   * There's an issue with writing and reading locks
   * 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
   * If a process depends on a lock and that lock is never freed, that process will starve
starve


Deadlock
Deadlock

Revision as of 17:25, 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 assignement:

 * 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
    • 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