PKUOS - Pintos
Pintos source browser for PKU Operating System course
priority-donate-one.c
Go to the documentation of this file.
1/** The main thread acquires a lock. Then it creates two
2 higher-priority threads that block acquiring the lock, causing
3 them to donate their priorities to the main thread. When the
4 main thread releases the lock, the other threads should
5 acquire it in priority order.
6
7 Based on a test originally submitted for Stanford's CS 140 in
8 winter 1999 by Matt Franklin <startled@leland.stanford.edu>,
9 Greg Hutchins <gmh@leland.stanford.edu>, Yu Ping Hu
10 <yph@cs.stanford.edu>. Modified by arens. */
11
12#include <stdio.h>
13#include "tests/threads/tests.h"
14#include "threads/init.h"
15#include "threads/synch.h"
16#include "threads/thread.h"
17
20
21void
23{
24 struct lock lock;
25
26 /* This test does not work with the MLFQS. */
28
29 /* Make sure our priority is the default. */
31
32 lock_init (&lock);
35 msg ("This thread should have priority %d. Actual priority: %d.",
38 msg ("This thread should have priority %d. Actual priority: %d.",
41 msg ("acquire2, acquire1 must already have finished, in that order.");
42 msg ("This should be the last line before finishing this test.");
43}
44
45static void
47{
48 struct lock *lock = lock_;
49
51 msg ("acquire1: got the lock");
53 msg ("acquire1: done");
54}
55
56static void
58{
59 struct lock *lock = lock_;
60
62 msg ("acquire2: got the lock");
64 msg ("acquire2: done");
65}
#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
void msg(const char *format,...)
Definition: lib.c:28
void test_priority_donate_one(void)
static thread_func acquire1_thread_func
The main thread acquires a lock.
static thread_func acquire2_thread_func
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