Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following code ( do not worry about the details of functions whose definitions are not provided to you - assume they do what

Consider the following code (do not worry about the details of functions whose definitions are not provided to you - assume they do what their name suggests and nothing more):

image text in transcribed

In order for this program to work correctly, condition variables need to be defined and appropriate wait & signal statements need to be added to the program.

Study the program and identify what comments on the left hand side match with what statements on the right hand side. Make sure that your answers reflect the meaning of condition variable names appropriately.

/* Definition of condition variable used in Action 1 below */

[ Choose ] num_items SZ num_items == 0 pthread_cond_wait(&buf_not_empty, &mutex); pthread_cond_wait(&buf_not_full, &mutex); pthread_cond_t buf_not_full = PTHREAD_COND_INITIALIZER; num_items 0 pthread_cond_signal(&buf_not_empty); num_items == SZ pthread_cond_t buf_not_empty = PTHREAD_COND_INITIALIZER;

/* Definition of condition variable used in Action 3 below */

[ Choose ] num_items SZ num_items == 0 pthread_cond_wait(&buf_not_empty, &mutex); pthread_cond_wait(&buf_not_full, &mutex); pthread_cond_t buf_not_full = PTHREAD_COND_INITIALIZER; num_items 0 pthread_cond_signal(&buf_not_empty); num_items == SZ pthread_cond_t buf_not_empty = PTHREAD_COND_INITIALIZER;

/* Condition 1 */

[ Choose ] num_items SZ num_items == 0 pthread_cond_wait(&buf_not_empty, &mutex); pthread_cond_wait(&buf_not_full, &mutex); pthread_cond_t buf_not_full = PTHREAD_COND_INITIALIZER; num_items 0 pthread_cond_signal(&buf_not_empty); num_items == SZ pthread_cond_t buf_not_empty = PTHREAD_COND_INITIALIZER;

/* Action 1 */

[ Choose ] num_items SZ num_items == 0 pthread_cond_wait(&buf_not_empty, &mutex); pthread_cond_wait(&buf_not_full, &mutex); pthread_cond_t buf_not_full = PTHREAD_COND_INITIALIZER; num_items 0 pthread_cond_signal(&buf_not_empty); num_items == SZ pthread_cond_t buf_not_empty = PTHREAD_COND_INITIALIZER;

/* Action 2 */

[ Choose ] num_items SZ num_items == 0 pthread_cond_wait(&buf_not_empty, &mutex); pthread_cond_wait(&buf_not_full, &mutex); pthread_cond_t buf_not_full = PTHREAD_COND_INITIALIZER; num_items 0 pthread_cond_signal(&buf_not_empty); num_items == SZ pthread_cond_t buf_not_empty = PTHREAD_COND_INITIALIZER;

/* Condition 2 */

[ Choose ] num_items SZ num_items == 0 pthread_cond_wait(&buf_not_empty, &mutex); pthread_cond_wait(&buf_not_full, &mutex); pthread_cond_t buf_not_full = PTHREAD_COND_INITIALIZER; num_items 0 pthread_cond_signal(&buf_not_empty); num_items == SZ pthread_cond_t buf_not_empty = PTHREAD_COND_INITIALIZER;

/* Action 3 */

[ Choose ] num_items SZ num_items == 0 pthread_cond_wait(&buf_not_empty, &mutex); pthread_cond_wait(&buf_not_full, &mutex); pthread_cond_t buf_not_full = PTHREAD_COND_INITIALIZER; num_items 0 pthread_cond_signal(&buf_not_empty); num_items == SZ pthread_cond_t buf_not_empty = PTHREAD_COND_INITIALIZER;

/* Action 4 */

[ Choose ] num_items SZ num_items == 0 pthread_cond_wait(&buf_not_empty, &mutex); pthread_cond_wait(&buf_not_full, &mutex); pthread_cond_t buf_not_full = PTHREAD_COND_INITIALIZER; num_items 0 pthread_cond_signal(&buf_not_empty); num_items == SZ pthread_cond_t buf_not_empty = PTHREAD_COND_INITIALIZER;

PreviousNext

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Multimedia Database Systems

Authors: V.S. Subrahmanian

1st Edition

1558604669, 978-1558604667

More Books

Students also viewed these Databases questions