Question
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):
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started