CS318 - Pintos
Pintos source browser for JHU CS318 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>
8 #include "tests/threads/tests.h"
9 #include "threads/init.h"
10 #include "threads/synch.h"
11 #include "threads/thread.h"
12 
14 
15 void
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);
27  lock_acquire (&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.",
36  lock_release (&lock);
37  msg ("acquire must already have finished.");
38  msg ("Main thread should have priority %d. Actual priority: %d.",
40 }
41 
42 static void
43 acquire_thread_func (void *lock_)
44 {
45  struct lock *lock = lock_;
46 
48  msg ("acquire: got the lock");
50  msg ("acquire: done");
51 }
lock_release
void lock_release(struct lock *lock)
Releases LOCK, which must be owned by the current thread.
Definition: synch.c:229
lock_init
void lock_init(struct lock *lock)
Initializes LOCK.
Definition: synch.c:176
test_priority_donate_lower
void test_priority_donate_lower(void)
Definition: priority-donate-lower.c:16
thread_get_priority
int thread_get_priority(void)
Returns the current thread's priority.
Definition: thread.c:343
init.h
ASSERT
#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
msg
void msg(const char *format,...)
Definition: lib.c:28
thread_mlfqs
bool thread_mlfqs
If false (default), use round-robin scheduler.
Definition: thread.c:60
thread_create
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
thread_set_priority
void thread_set_priority(int new_priority)
Sets the current thread's priority to NEW_PRIORITY.
Definition: thread.c:336
tests.h
acquire_thread_func
static thread_func acquire_thread_func
The main thread acquires a lock.
Definition: priority-donate-lower.c:13
thread_func
void thread_func(void *aux)
Definition: thread.h:116
lock_acquire
void lock_acquire(struct lock *lock)
Acquires LOCK, sleeping until it becomes available if necessary.
Definition: synch.c:193
thread.h
synch.h
lock
Lock.
Definition: synch.h:21
PRI_DEFAULT
#define PRI_DEFAULT
Default priority.
Definition: thread.h:24