[SOLVED] CS代考计算机代写 /* Tests that cond_signal() wakes up the highest-priority thread

30 $

File Name: CS代考计算机代写_/*_Tests_that_cond_signal()_wakes_up_the_highest-priority_thread.zip
File Size: 828.96 KB

SKU: 0887492298 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


/* Tests that cond_signal() wakes up the highest-priority thread
waiting in cond_wait(). */

#include
#include “tests/threads/tests.h”
#include “threads/init.h”
#include “threads/malloc.h”
#include “threads/condvar.h”
#include “threads/lock.h”
#include “threads/thread.h”
#include “devices/timer.h”

static thread_func priority_condvar_thread;
static struct lock lock;
static struct condvar condvar;

void
test_priority_condvar(void)
{
int i;

/* This test does not work with the MLFQS. */
ASSERT(!thread_mlfqs);

lock_init(&lock);
condvar_init(&condvar);

thread_set_priority(PRI_MIN);
for (i = 0; i < 10; i++) {int priority = PRI_DEFAULT – (i + 7) % 10 – 1;char name[16];snprintf(name, sizeof name, “priority %d”, priority);thread_create(name, priority, priority_condvar_thread, NULL);}for (i = 0; i < 10; i++) {lock_acquire(&lock);msg(“Signaling…”);condvar_signal(&condvar, &lock);lock_release(&lock);}}static voidpriority_condvar_thread(void *aux UNUSED){msg(“Thread %s starting.”, thread_name());lock_acquire(&lock);condvar_wait(&condvar, &lock);msg(“Thread %s woke up.”, thread_name());lock_release(&lock);}

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS代考计算机代写 /* Tests that cond_signal() wakes up the highest-priority thread
30 $