PKUOS - Pintos
Pintos source browser for PKU Operating System course
priority-donate-multiple2.c
Go to the documentation of this file.
1/** The main thread acquires locks A and B, then it creates three
2 higher-priority threads. The first two of these threads block
3 acquiring one of the locks and thus donate their priority to
4 the main thread. The main thread releases the locks in turn
5 and relinquishes its donated priorities, allowing the third thread
6 to run.
7
8 In this test, the main thread releases the locks in a different
9 order compared to priority-donate-multiple.c.
10
11 Written by Godmar Back <gback@cs.vt.edu>.
12 Based on a test originally submitted for Stanford's CS 140 in
13 winter 1999 by Matt Franklin <startled@leland.stanford.edu>,
14 Greg Hutchins <gmh@leland.stanford.edu>, Yu Ping Hu
15 <yph@cs.stanford.edu>. Modified by arens. */
16
17#include <stdio.h>
18#include "tests/threads/tests.h"
19#include "threads/init.h"
20#include "threads/synch.h"
21#include "threads/thread.h"
22
26
27void
29{
30 struct lock a, b;
31
32 /* This test does not work with the MLFQS. */
34
35 /* Make sure our priority is the default. */
37
38 lock_init (&a);
39 lock_init (&b);
40
41 lock_acquire (&a);
42 lock_acquire (&b);
43
45 msg ("Main thread should have priority %d. Actual priority: %d.",
47
49
51 msg ("Main thread should have priority %d. Actual priority: %d.",
53
54 lock_release (&a);
55 msg ("Main thread should have priority %d. Actual priority: %d.",
57
58 lock_release (&b);
59 msg ("Threads b, a, c should have just finished, in that order.");
60 msg ("Main thread should have priority %d. Actual priority: %d.",
62}
63
64static void
65a_thread_func (void *lock_)
66{
67 struct lock *lock = lock_;
68
70 msg ("Thread a acquired lock a.");
72 msg ("Thread a finished.");
73}
74
75static void
76b_thread_func (void *lock_)
77{
78 struct lock *lock = lock_;
79
81 msg ("Thread b acquired lock b.");
83 msg ("Thread b finished.");
84}
85
86static void
88{
89 msg ("Thread c finished.");
90}
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
Definition: debug.h:31
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
Definition: debug.h:7
void msg(const char *format,...)
Definition: lib.c:28
static thread_func c_thread_func
static thread_func a_thread_func
The main thread acquires locks A and B, then it creates three higher-priority threads.
static thread_func b_thread_func
void test_priority_donate_multiple2(void)
#define NULL
Definition: stddef.h:4
Lock.
Definition: synch.h:22
void lock_release(struct lock *lock)
Releases LOCK, which must be owned by the current thread.
Definition: synch.c:229
void lock_init(struct lock *lock)
Initializes LOCK.
Definition: synch.c:176
void lock_acquire(struct lock *lock)
Acquires LOCK, sleeping until it becomes available if necessary.
Definition: synch.c:193
bool thread_mlfqs
If false (default), use round-robin scheduler.
Definition: thread.c:60
int thread_get_priority(void)
Returns the current thread's priority.
Definition: thread.c:343
tid_t thread_create(const char *name, int priority, thread_func *function, void *aux)
Creates a new kernel thread named NAME with the given initial PRIORITY, which executes FUNCTION passi...
Definition: thread.c:166
#define PRI_DEFAULT
Default priority.
Definition: thread.h:24
void thread_func(void *aux)
Definition: thread.h:116