logo

Crowdly

Browser

Add to Chrome

2025W Operating Systems (CS-3520-01)

Looking for 2025W Operating Systems (CS-3520-01) test answers and solutions? Browse our comprehensive collection of verified answers for 2025W Operating Systems (CS-3520-01) at moodle31.upei.ca.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

In our working producer and consumer solutions with a single buffer slot using condition variables, we used two condition variables. Why was the second condition variable necessary?

0%
0%
0%
0%
View this question

When using a semaphore to ensure the child thread runs before the parent executes further as in the code snippet below, what value should the semaphore be initialized too (i.e., what should X be)?

sem_t s;

void *child(void *arg) {

printf("child");

sem_post(&s); // signal here: child is done

return NULL;

}

int main(int argc, char *argv[]) {

sem_init(&s, 0, X); // what should X be?

printf("parent: begin");

pthread_t c;

pthread_create(c, NULL, child, NULL);

sem_wait(&s); // wait here for child

printf("parent: end");

return 0;

}

View this question

The code for our reader-writer lock from class/the textbook is shown below. What is the main disadvantage of this code?

typedef struct _rwlock_t {

sem_t lock; // binary semaphore (basic lock)

sem_t writelock; // used to allow ONE writer or MANY readers

int readers; // count of readers reading in critical section

} rwlock_t;

void rwlock_init(rwlock_t *rw) {

rw->readers = 0;

sem_init(&rw->lock, 0, 1);

sem_init(&rw->writelock, 0, 1);

}

void rwlock_acquire_readlock(rwlock_t *rw) {

sem_wait(&rw->lock);

rw->readers++;

if (rw->readers == 1)

sem_wait(&rw->writelock); // first reader acquires writelock

sem_post(&rw->lock);

}

void rwlock_release_readlock(rwlock_t *rw) {

sem_wait(&rw->lock);

rw->readers--;

if (rw->readers == 0)

sem_post(&rw->writelock); // last reader releases writelock

sem_post(&rw->lock);

}

void rwlock_acquire_writelock(rwlock_t *rw) {

sem_wait(&rw->writelock);

}

void rwlock_release_writelock(rwlock_t *rw) {

sem_post(&rw->writelock);

}

0%
0%
0%
0%
View this question

Which of the following is true about the advantages and disadvantages of using pthread_cond_broadcast() over pthread_cond_signal()?

View this question

When using a semaphore as a lock as in the code snippet below, what value should the semaphore be initialized too (i.e., what should X be)?

1 sem_t m;

2 sem_init(&m, 0, X);

3

4 sem_wait(&m);

5 //critical section here

6 sem_post(&m);

View this question
Which of the following is NOT one of the four conditions that must be met for deadlock to occur?
0%
0%
0%
0%
0%
View this question

When the value of a semaphore is negative what does this number indicate?

View this question

Want instant access to all verified answers on moodle31.upei.ca?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome