PKUOS - Pintos
Pintos source browser for PKU Operating System course
priority-condvar.c
Go to the documentation of this file.
1/** Tests that cond_signal() wakes up the highest-priority thread
2 waiting in cond_wait(). */
3
4#include <stdio.h>
6#include "threads/init.h"
7#include "threads/malloc.h"
8#include "threads/synch.h"
9#include "threads/thread.h"
10#include "devices/timer.h"
11
13static struct lock lock;
14static struct condition condition;
15
16void
18{
19 int i;
20
21 /* This test does not work with the MLFQS. */
23
24 lock_init (&lock);
26
28 for (i = 0; i < 10; i++)
29 {
30 int priority = PRI_DEFAULT - (i + 7) % 10 - 1;
31 char name[16];
32 snprintf (name, sizeof name, "priority %d", priority);
34 }
35
36 for (i = 0; i < 10; i++)
37 {
39 msg ("Signaling...");
42 }
43}
44
45static void
47{
48 msg ("Thread %s starting.", thread_name ());
51 msg ("Thread %s woke up.", thread_name ());
53}
#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
char * name[]
Definition: insult.c:47
int snprintf(char *buffer, size_t buf_size, const char *format,...)
Like printf(), except that output is stored into BUFFER, which must have space for BUF_SIZE character...
Definition: stdio.c:62
void msg(const char *format,...)
Definition: lib.c:28
void test_priority_condvar(void)
static thread_func priority_condvar_thread
Tests that cond_signal() wakes up the highest-priority thread waiting in cond_wait().
#define NULL
Definition: stddef.h:4
Condition variable.
Definition: synch.h:35
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 cond_wait(struct condition *cond, struct lock *lock)
Atomically releases LOCK and waits for COND to be signaled by some other piece of code.
Definition: synch.c:288
void cond_signal(struct condition *cond, struct lock *lock UNUSED)
If any threads are waiting on COND (protected by LOCK), then this function signals one of them to wak...
Definition: synch.c:312
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
void cond_init(struct condition *cond)
Initializes condition variable COND.
Definition: synch.c:260
bool thread_mlfqs
If false (default), use round-robin scheduler.
Definition: thread.c:60
const char * thread_name(void)
Returns the name of the running thread.
Definition: thread.c:247
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
#define PRI_MIN
Thread priorities.
Definition: thread.h:23