DOC PREVIEW
MIT 6 033 - LECTURE NOTES

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

6.033 Spring 2009 Robert Morris Lecture 7 ThreadsRemember: 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)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()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) suspend resume version 1Send 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()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/Notifywait(cvar, lock): acquire(t_lock) release(lock) threads[id].cvar = cvar threads[id].state = WAITING yield() release(t_lock) acquire(lock)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)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 loopyield(): 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


View Full Document

MIT 6 033 - LECTURE NOTES

Documents in this Course
TRIPLET

TRIPLET

12 pages

End Layer

End Layer

11 pages

Quiz 1

Quiz 1

4 pages

Threads

Threads

18 pages

Quiz I

Quiz I

15 pages

Atomicity

Atomicity

10 pages

QUIZ I

QUIZ I

7 pages

Load more
Download LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?