CS318 - Pintos
Pintos source browser for JHU CS318 course
|
Go to the documentation of this file.
62 msg (
"Creating %d threads to sleep %d times each.", thread_cnt,
iterations);
63 msg (
"Thread 0 sleeps 10 ticks each time,");
64 msg (
"thread 1 sleeps 20 ticks each time, and so on.");
65 msg (
"If successful, product of iteration count and");
66 msg (
"sleep duration will appear in nondescending order.");
69 threads =
malloc (
sizeof *threads * thread_cnt);
71 if (threads ==
NULL || output ==
NULL)
72 PANIC (
"couldn't allocate memory for test");
78 test.output_pos = output;
82 for (i = 0; i < thread_cnt; i++)
105 for (op = output; op <
test.output_pos; op++)
110 ASSERT (*op >= 0 && *op < thread_cnt);
115 msg (
"thread %d: duration=%d, iteration=%d, product=%d",
118 if (new_prod >= product)
121 fail (
"thread %d woke up out of order (%d > %d)!",
122 t->
id, product, new_prod);
126 for (i = 0; i < thread_cnt; i++)
128 fail (
"thread %d woke up %d times instead of %d",
144 for (i = 1; i <=
test->iterations; i++)
149 *
test->output_pos++ = t->
id;
void * malloc(size_t size)
Obtains and returns a new block of at least SIZE bytes.
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...
void lock_release(struct lock *lock)
Releases LOCK, which must be owned by the current thread.
void lock_init(struct lock *lock)
Initializes LOCK.
void free(void *p)
Frees block P, which must have been previously allocated with malloc(), calloc(), or realloc().
#define PANIC(...)
Halts the OS, printing the source file name, line number, and function name, plus a user-specific mes...
struct sleep_test * test
Info shared between all threads.
signed long long int int64_t
void test_alarm_multiple(void)
int * output_pos
Current position in output buffer.
static void sleeper(void *)
Sleeper thread.
void test(void)
Test the linked list implementation.
void timer_sleep(int64_t ticks)
Sleeps for approximately TICKS timer ticks.
int64_t timer_ticks(void)
Returns the number of timer ticks since the OS booted.
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
void fail(const char *format,...)
int64_t start
Current time at start of test.
int iterations
Number of iterations per thread.
struct lock output_lock
Lock protecting output buffer.
void msg(const char *format,...)
int iterations
Iterations counted so far.
bool thread_mlfqs
If false (default), use round-robin scheduler.
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...
void test_alarm_single(void)
static void test_sleep(int thread_cnt, int iterations)
Creates N threads, each of which sleeps a different, fixed duration, M times.
void lock_acquire(struct lock *lock)
Acquires LOCK, sleeping until it becomes available if necessary.
Information about an individual thread in the test.
int duration
Number of ticks to sleep.
#define PRI_DEFAULT
Default priority.
Information about the test.