PKUOS - Pintos
Pintos source browser for PKU Operating System course
|
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
#include "threads/synch.h"
#include "threads/thread.h"
Go to the source code of this file.
Data Structures | |
struct | lock_pair |
Macros | |
#define | NESTING_DEPTH 8 |
The main thread set its priority to PRI_MIN and creates 7 threads (thread 1..7) with priorities PRI_MIN + 3, 6, 9, 12, ... The main thread initializes 8 locks: lock 0..7 and acquires lock 0. More... | |
Functions | |
void | test_priority_donate_chain (void) |
static void | donor_thread_func (void *locks_) |
static void | interloper_thread_func (void *arg_ UNUSED) |
Variables | |
static thread_func | donor_thread_func |
static thread_func | interloper_thread_func |
#define NESTING_DEPTH 8 |
The main thread set its priority to PRI_MIN and creates 7 threads (thread 1..7) with priorities PRI_MIN + 3, 6, 9, 12, ... The main thread initializes 8 locks: lock 0..7 and acquires lock 0.
When thread[i] starts, it first acquires locki Subsequently, thread[i] attempts to acquire lock[i-1], which is held by thread[i-1], except for lock[0], which is held by the main thread. Because the lock is held, thread[i] donates its priority to thread[i-1], which donates to thread[i-2], and so on until the main thread receives the donation.
After threads[1..7] have been created and are blocked on locks[0..7], the main thread releases lock[0], unblocking thread[1], and being preempted by it. Thread[1] then completes acquiring lock[0], then releases lock[0], then releases lock[1], unblocking thread[2], etc. Thread[7] finally acquires & releases lock[7] and exits, allowing thread[6], then thread[5] etc. to run and exit until finally the main thread exits.
In addition, interloper threads are created at priority levels p = PRI_MIN + 2, 5, 8, 11, ... which should not be run until the corresponding thread with priority p + 1 has finished.
Written by Godmar Back gback @cs. vt.ed u
Definition at line 33 of file priority-donate-chain.c.
|
static |
Definition at line 86 of file priority-donate-chain.c.
References lock_acquire(), lock_release(), msg(), NESTING_DEPTH, thread_get_priority(), and thread_name().
|
static |
Definition at line 109 of file priority-donate-chain.c.
References msg(), and thread_name().
void test_priority_donate_chain | ( | void | ) |
Definition at line 45 of file priority-donate-chain.c.
|
static |
Definition at line 41 of file priority-donate-chain.c.
|
static |
Definition at line 42 of file priority-donate-chain.c.