1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ryzh [129]
3 years ago
7

The producer thread will alternate between sleeping for a random period of time and inserting a random integer into the buffer.

Random numbers will be produced using the rand_r(unsigned int *seed) function, which produces random integers between 0 and RAND_MAX safely in multithreaded processes. The consumer will also sleep for a random period of time and, upon awakening, will attempt to remove an item from the buffer. An outline of the producer and consumer threads appears as:
Computers and Technology
1 answer:
Llana [10]3 years ago
3 0

Answer:

// Producer Thread

void *producer(void *param) {

buffer_item item;

while (true) {

item = rand() % 100;

sem_wait(&empty);

pthread_mutex_lock(&mutex);

if (insert_item(item))

printf("Can't insert item\n");

else

printf("Producer %d: produced %d\n", *((int*)param), item);

pthread_mutex_unlock(&mutex);

sem_post(&full);

}

}

// Consumer Thread

void *consumer(void *param) {

while (true) {

buffer_item item = NULL;

if (in > 0)

item = buffer[in - 1];

sem_wait(&full);

pthread_mutex_lock(&mutex);

if (remove_item(&item))

printf("Can't remove item\n");

else

printf("Consumer %d: consumed %d\n", *((int*)param), item);

pthread_mutex_unlock(&mutex);

sem_post(&empty);

}

}

Explanation:

An outline of the producer and consumer threads appears as shown above.

You might be interested in
Carbon copy others who are..
My name is Ann [436]

Answer:

Is it Multiple Choice Question?

5 0
2 years ago
Read 2 more answers
Complete the following Programming Assignment using Recursion. Use good programming style and all the concepts previously covere
Likurg_2 [28]

Answer:

Explanation:

public class Ackermann {

   public static int ackermann's(int m, int n) {

       if (m == 0) {

           return n + 1;

       } else if (n == 0) {

           return ackermann's(m-1, 1);

       } else {

           return ackermann(m - 1, ackermann(m, n - 1));

       }

   }

   public static void main(String[] args) {

       System.out.println(ackermann(0, 0));

       System.out.println(ackermann(0, 1));

       System.out.println(ackermann(1, 1));

       System.out.println(ackermann(1, 2));

       System.out.println(ackermann(1, 3));

       System.out.println(ackermann(2, 2));

       System.out.println(ackermann(3, 2));

   }

}

1

2

3

4

5

6

7

29

Process finished with exit code 0

6 0
3 years ago
Question 5 (frue/False Worth 3 points)
azamat

<em><u>true</u></em>

Explanation:

<em><u>because</u></em><em><u> </u></em><em><u>logical</u></em><em><u> </u></em><em><u>errors</u></em><em><u> </u></em><em><u>are</u></em><em><u> </u></em><em><u>made</u></em><em><u> </u></em><em><u>to</u></em><em><u> </u></em><em><u>be</u></em><em><u> </u></em><em><u>unexpected</u></em><em><u> </u></em><em><u>it</u></em><em><u> </u></em><em><u>was</u></em><em><u> </u></em><em><u>before</u></em>

5 0
3 years ago
What should every Software Engineer know about Software Architecture?
Alenkinab [10]
<span>!UML (all of them)
2.Flowchart (more for understanding a real world process of some kind; like a business process)
3.Data model including Bachman (if you don't need to at least understand your data, how it is stored versus a model, i.e., Bachman then you are doing it wrong and your schema could be simplistic)
This is 3 different examples</span>
6 0
3 years ago
The system should enable the staff of each academic department to examine the courses offered by their department, add and remov
Ganezh [65]

Answer:

See attached picture.

Explanation:

See attached picture.

3 0
3 years ago
Other questions:
  • This is question 2.5 Computer Science and I don't understand what is wrong<br><br>​
    15·1 answer
  • The array s of ints contain integers each of which is between 1 and 1000 (inclusive). write code that stores in the variable ord
    9·1 answer
  • How is a recession determined?
    10·1 answer
  • Examine the following declarations and definitions for the array-based implementations for the Stack and Queue ADTs. Assume that
    14·1 answer
  • Drawing programs typically create images using mathematical formulas, instead of by coloring pixels, so images can be resized an
    12·1 answer
  • In black and white,<br><br> we must be more conscious of image
    11·1 answer
  • What is the by stander effect
    9·1 answer
  • Is a collection of information stored under a single nam​
    6·2 answers
  • Which alignment aligns text to the left and right side margins?
    15·1 answer
  • HOW TO DISCONNECT A MONITOR FROM A SYSTEM UNIT
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!