1 / 10

6.033 Spring 2009

6.033 Spring 2009. Robert Morris Lecture 7 Threads. Remember: Send. send(p, m): while true: acquire(p.lock) if p.in - p.out < N: p.buffer[p.in mod N]  m p.in  p.in + 1 release(p.lock) return release(p.lock).

inga
Download Presentation

6.033 Spring 2009

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 6.033 Spring 2009 Robert Morris Lecture 7 Threads

  2. Remember: Send send(p, m): while true: acquire(p.lock) if p.in - p.out < N: p.buffer[p.in mod N]  m p.in  p.in + 1 release(p.lock) return release(p.lock)

  3. Send / Receive with Yield send(p, m): while true: if something to do: do it else: yield() receive(p): while true: if something to do: do it else: yield()

  4. yield(): acquire(t_lock) id = cpus[CPU()].thread threads[id].state = RUNNABLE threads[id].sp = SP do: id = (id + 1) mod N while threads[id].state != RUNNABLE threads[id].state = RUNNING SP = threads[id].sp cpus[CPU()].thread = id release(t_lock) version 1 suspend resume

  5. Send with Yield send(p, m): while true: acquire(p.lock) if p.in - p.out < N: p.buffer[p.in mod N]  m p.in  p.in + 1 release(p.lock) return release(p.lock) yield()

  6. send(p, m): acquire(p.lock) while p.in - p.out == N: wait(p.notfull, p.lock) p.buffer[p.in mod N]  m p.in  p.in + 1 notify(p.notempty) release(p.lock) Send with Wait/Notify

  7. wait(cvar, lock): acquire(t_lock) release(lock) threads[id].cvar = cvar threads[id].state = WAITING yield() release(t_lock) acquire(lock)

  8. wait(cvar, lock): acquire(t_lock) release(lock) threads[id].cvar = cvar threads[id].state = WAITING yield() release(t_lock) acquire(lock) notify(cvar): acquire(t_lock) for i = 0 to N-1: if threads[i].cvar == cvar and threads[i].state == WAITING: threads[i].state = RUNNABLE release(t_lock)

  9. yield(): acquire(t_lock) id = cpus[CPU()].thread threads[id].state = RUNNABLE threads[id].sp = SP do: id = (id + 1) mod N while threads[id].state != RUNNABLE threads[id].state = RUNNING SP = threads[id].sp cpus[CPU()].thread = id release(t_lock) version 1 idle loop

  10. yield(): id = cpus[CPU()].thread threads[id].sp = SP SP = cpus[CPU()].stack do: id = (id + 1) mod N release(t_lock) acquire(t_lock) while threads[id].state != RUNNABLE threads[id].state = RUNNING SP = threads[id].sp cpus[CPU()].thread = id version 2 idle loop

More Related