DOC PREVIEW
Stanford CS 140 - Uniprocessor Locks

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 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 9 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 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Uniprocessor Locks, v1Uniprocessor Locks, v2Multiprocessor Locks, v1Multiprocessor Locks, v2Multiprocessor Locks, v3Multiprocessor Locks, v4Slide 7Slide 8Slide 9CS 140 Lecture Notes: Lock Implementation Slide 1Uniprocessor Locks, v1void lock_acquire(struct lock *l) { while (1) { Disable interrupts; if (!l->locked) { l->locked = 1; Enable interrupts; return; } Enable interrupts; }}void lock_release(struct lock *l) { Disable interrupts; l->locked = 0; Enable interrupts;}struct lock { int locked;};CS 140 Lecture Notes: Lock Implementation Slide 2Uniprocessor Locks, v2void lock_acquire(struct lock *l) { Disable interrupts; if (!l->locked) { l->locked = 1; } else { queue_add(&l->q, thread_current()); thread_block(); } Enable interrupts;}void lock_release(struct lock *l) { Disable interrupts; if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock(queue_remove(&l->q)); } Enable interrupts;}struct lock { int locked; struct queue q;};CS 140 Lecture Notes: Lock Implementation Slide 3Multiprocessor Locks, v1struct lock { int locked;};void lock_acquire( struct lock *l) { while (aswap(&l->locked, 1)) { /* Do nothing */ }}void lock_release( struct lock *l) { l->locked = 0;}CS 140 Lecture Notes: Lock Implementation Slide 4Multiprocessor Locks, v2struct lock { int locked; struct queue q;};void lock_acquire( struct lock *l) { if (aswap(&l->locked, 1) { queue_add(&l->q, thread_current()); thread_block(); }}void lock_release( struct lock *l) { if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock( queue_remove(&l->q)); }}CS 140 Lecture Notes: Lock Implementation Slide 5Multiprocessor Locks, v3struct lock { int locked; struct queue q; int sync;};void lock_acquire( struct lock *l) { while (aswap(&l->sync, 1) { /* Do nothing */ } if (!l->locked) { l->locked = 1; l->sync = 0; } else { queue_add(&l->q, thread_current()); l->sync = 0; thread_block(); }}void lock_release( struct lock *l) { while (aswap(&l->sync, 1) { /* Do nothing */ } if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock( queue_remove(&l->q)); } l->sync = 0;}CS 140 Lecture Notes: Lock Implementation Slide 6Multiprocessor Locks, v4struct lock { int locked; struct queue q; int sync;};void lock_acquire( struct lock *l) { Disable interrupts; while (aswap(&l->sync, 1) { /* Do nothing */ } if (!l->locked) { l->locked = 1; l->sync = 0; } else { queue_add(&l->q, thread_current()); l->sync = 0; thread_block(); } Enable interrupts;}void lock_release( struct lock *l) { Disable interrupts; while (aswap(&l->sync, 1) { /* Do nothing */ } if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock( queue_remove(&l->q)); } l->sync = 0; Enable interrupts;}CS 140 Lecture Notes: Lock Implementation Slide 7CS 140 Lecture Notes: Lock Implementation Slide 8Multiprocessor Locks, v3struct lock { int locked; struct queue q;};void lock_acquire( struct lock *l) { Disable interrupts; if (aswap(&l->locked, 1) { queue_add(&l->q, thread_current()); thread_block(); } Enable interrupts;}void lock_release( struct lock *l) { Disable interrupts; if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock( queue_remove(&l->q)); } Enable interrupts;}CS 140 Lecture Notes: Lock Implementation Slide 9Multiprocessor Locks, v4struct lock { int locked; struct queue q; int sync;};void lock_acquire( struct lock *l) { Disable interrupts; while (aswap(&l->sync, 1) { /* Do nothing */ } if (!l->locked) { l->locked = 1; l->sync = 0; } else { queue_add(&l->q, thread_current()); l->sync = 0; thread_block(); } Enable interrupts;}void lock_release( struct lock *l) { Disable interrupts; while (aswap(&l->sync, 1) { /* Do nothing */ } if (queue_empty(&l->q) { l->locked = 0; } else { thread_unblock( queue_remove(&l->q)); } l->sync = 0; Enable


View Full Document

Stanford CS 140 - Uniprocessor Locks

Documents in this Course
Homework

Homework

25 pages

Notes

Notes

8 pages

Load more
Download Uniprocessor Locks
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 Uniprocessor Locks 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 Uniprocessor Locks 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?