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
If non-series-rated overcurrent devices (standard molded-case circuit breakers) are to be installed in the main switchboard, bre
const2013 [10]

Breakers with adequate short-circuit must be installed in the panelboards.

<h3>What are these equipment about?</h3>

Common Overcurrent Protection Devices (OCPDs) are known to be Breakers or fuses that are often used  to protect the full unit from too much current.

Note that Equipment such as switchboards and panelboards are often installed in an electrical system and they have to be of adequate measure of short-circuit current condition.

Learn more about overcurrent devices  from

brainly.com/question/14284905

3 0
2 years ago
What is bespoke software???​
denis-greek [22]

Answer:

custom-built to address the specific requirements of a business

Explanation:

5 0
3 years ago
Read 2 more answers
What is the definition of framerate?
ra1l [238]

Answer: The frequency at which frames in a television picture, film, or video sequence are displayed.

7 0
3 years ago
What is a project?
Elan Coil [88]
Simply put, a project is a series of tasks that need to be completed in order to reach a specific outcome. A project can also be defined as a set of inputs and outputs required to achieve a particular goal. Projects can range from simple to complex and can be managed by one person or a hundred.
5 0
3 years ago
Read 2 more answers
A secret information for using email is ____________
babymother [125]

wekipedia \:

6 0
3 years ago
Read 2 more answers
Other questions:
  • If you wanted to insert pictures into a presentation which tab would you use
    6·2 answers
  • Cattell classified projective tests, such as the rorschach inkblot test, as:
    13·1 answer
  • Write a java program that declares an array "alpha" of 50 elements of type "double". Initialize the array so that the first 25 e
    11·1 answer
  • You need to deploy a new cloud-based windows intune deployment to manage mobile devices in your organization. drag and drop the
    5·1 answer
  • The continue statement _________.
    11·1 answer
  • Bullet points on a slide should be limited to _____.<br><br> A. 2<br> B. 4<br> C. 8<br> D. 10
    7·1 answer
  • Which componet is the smallest unit in a spreadsheet
    15·1 answer
  • Commercial technical data and commercial software:_________.
    11·1 answer
  • A student is having trouble finding enough time in his busy schedule to work on his school science project. He has a demanding s
    5·2 answers
  • As we’ve discussed, computer programs are considered creative works and are protected by copyright. That means those programs be
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!