본문 바로가기

전체 글195

7. Deadlock The deadlock problem: Systems usually have multiple locks Threads often need to hold multiple locks at the same time. Deadlock definition: A collection of threads are all blocked. Each thread is waiting for a resource owned by one of the other threads. Since all therads are blocked, none can release their resources. Simple examples: Thread A Thread B lock_acquire(l1); lock_acquire(l2); lock_acqu.. 2022. 11. 13.
6. Implementing Locks How to implement locks and condition variables (inside the operating system)? Uniprocessor solution: just disable interrupts struct lock { int locked; struct queue q; }; void lock_acquire(struct lock *l) { intr_disable(); if (!l->locked) { l->locked = 1; } else { queue_add(&l->q, thread_current()); thread_block(); } intr_enable(); } void lock_release(struct lock *l) { intr_disable(); if (queue_e.. 2022. 11. 13.
5. Scheduling Resources fall into two classes: preemptible: can take resource away, use it for something else, then give it back later. Example: processor or I/O chanel. Non-preemptible: once given, it can't be reused until thread gives it back. Example: file space. OS makes two related kinds of decisions about resources: Allocation: who gets what. Given a set of requests for resources, which processes shoulc.. 2022. 11. 13.
4. Locks and Condition Variables Locks Locks: an object that can only be owned by a single thread at any given time. Basic operations on a lock: acquire: mark the lock as owned by the current thread; if some other thread already owns the lock then first wait until the lock is free. Lock typically includes a queue to keep track of multiple waiting threads. release: mark the lock as free (it must currently be owned by the calling.. 2022. 11. 12.