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?
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);
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);
}
When the value of a semaphore is negative what does this number indicate?
Which of the following is true about the advantages and disadvantages of using pthread_cond_broadcast() over pthread_cond_signal()?
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!