PKUOS - Pintos
Pintos source browser for PKU Operating System course
priority-donate-lower.c
Go to the documentation of this file.
1/** The main thread acquires a lock. Then it creates a
2 higher-priority thread that blocks acquiring the lock, causing
3 it to donate their priorities to the main thread. The main
4 thread attempts to lower its priority, which should not take
5 effect until the donation is released. */
6
7#include <stdio.h>
9#include "threads/init.h"
10#include "threads/synch.h"
11#include "threads/thread.h"
12
14
15void
17{
18 struct lock lock;
19
20 /* This test does not work with the MLFQS. */
22
23 /* Make sure our priority is the default. */
25
26 lock_init (&lock);
29 msg ("Main thread should have priority %d. Actual priority: %d.",
31
32 msg ("Lowering base priority...");
34 msg ("Main thread should have priority %d. Actual priority: %d.",
37 msg ("acquire must already have finished.");
38 msg ("Main thread should have priority %d. Actual priority: %d.",
40}
41
42static void
43acquire_thread_func (void *lock_)
44{
45 struct lock *lock = lock_;
46
48 msg ("acquire: got the lock");
50 msg ("acquire: done");
51}
#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
static thread_func acquire_thread_func
The main thread acquires a lock.
void test_priority_donate_lower(void)
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
void thread_set_priority(int new_priority)
Sets the current thread's priority to NEW_PRIORITY.
Definition: thread.c:336
#define PRI_DEFAULT
Default priority.
Definition: thread.h:24
void thread_func(void *aux)
Definition: thread.h:116