[SOLVED] CS代考计算机代写 /* Tests that the highest-priority thread waiting on a semaphore

30 $

File Name: CS代考计算机代写_/*_Tests_that_the_highest-priority_thread_waiting_on_a_semaphore.zip
File Size: 828.96 KB

SKU: 4082743266 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


/* Tests that the highest-priority thread waiting on a semaphore
is the first to wake up. */

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

static thread_func priority_sema_thread;
static struct semaphore sema;

void
test_priority_sema (void)
{
int i;

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

semaphore_init (&sema, 0);
thread_set_priority (PRI_MIN);
for (i = 0; i < 10; i++) {int priority = PRI_DEFAULT – (i + 3) % 10 – 1;char name[16];snprintf (name, sizeof name, “priority %d”, priority);thread_create (name, priority, priority_sema_thread, NULL);}for (i = 0; i < 10; i++) {semaphore_up (&sema);msg (“Back in main thread.”); }}static voidpriority_sema_thread (void *aux UNUSED) {semaphore_down (&sema);msg (“Thread %s woke up.”, thread_name ());}

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 the highest-priority thread waiting on a semaphore
30 $