PKUOS - Pintos
Pintos source browser for PKU Operating System course
Data Structures | Macros | Functions | Variables
priority-donate-chain.c File Reference
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
#include "threads/synch.h"
#include "threads/thread.h"
Include dependency graph for priority-donate-chain.c:

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
 

Macro Definition Documentation

◆ NESTING_DEPTH

#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.nosp@m.@cs..nosp@m.vt.ed.nosp@m.u

Definition at line 33 of file priority-donate-chain.c.

Function Documentation

◆ donor_thread_func()

static void donor_thread_func ( void *  locks_)
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().

Here is the call graph for this function:

◆ interloper_thread_func()

static void interloper_thread_func ( void *arg_  UNUSED)
static

Definition at line 109 of file priority-donate-chain.c.

References msg(), and thread_name().

Here is the call graph for this function:

◆ test_priority_donate_chain()

void test_priority_donate_chain ( void  )

Definition at line 45 of file priority-donate-chain.c.

Variable Documentation

◆ donor_thread_func

thread_func donor_thread_func
static

Definition at line 41 of file priority-donate-chain.c.

◆ interloper_thread_func

thread_func interloper_thread_func
static

Definition at line 42 of file priority-donate-chain.c.