1 / 9

Uniprocessor Locks, v1

void 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) {

cheung
Download Presentation

Uniprocessor Locks, v1

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. void 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; }; Uniprocessor Locks, v1 CS 140 Lecture Notes: Lock Implementation

  2. void 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; }; Uniprocessor Locks, v2 CS 140 Lecture Notes: Lock Implementation

  3. struct 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; } Multiprocessor Locks, v1 CS 140 Lecture Notes: Lock Implementation

  4. struct 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)); } } Multiprocessor Locks, v2 CS 140 Lecture Notes: Lock Implementation

  5. struct 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; } Multiprocessor Locks, v3 CS 140 Lecture Notes: Lock Implementation

  6. struct 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; } Multiprocessor Locks, v4 CS 140 Lecture Notes: Lock Implementation

  7. CS 140 Lecture Notes: Lock Implementation

  8. struct 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; } Multiprocessor Locks, v3 CS 140 Lecture Notes: Lock Implementation

  9. struct 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; } Multiprocessor Locks, v4 CS 140 Lecture Notes: Lock Implementation

More Related