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
Fifty part-time students were asked how many courses they were taking this term. The (incomplete) results are shown below. Need
Ne4ueva [31]

Answer:

The answer for B is 10% and for C is 40%.

Explanation:

To get the percentage for B you take the the frequecy of students taking 2 courses (5) and multiply it by 100 then you divide it by whole number of students.

For C you do the after adding the number of students taking 1 or 2 courses (20).

5 0
3 years ago
Compare and contrast between first and second generation of computer<br>​
noname [10]
Frist gen of computers took forever to load and would crash if someone els in the house picked up the phone now adays are computers are in our pockets. There our phones and they rarely if ever crash
8 0
3 years ago
Which of the following best describes the relationship between if/else and switch statements :
kvasek [131]
I want to say ‘A’ since if/else and switch statements are both conditional statements.
7 0
3 years ago
Lol who look at this so funny
seraphim [82]

Answer:

wow my humor is bad then.

6 0
3 years ago
Which part(s) of CAIN is realized through the use of message digest functions and hashes?
KonstantinChe [14]

Answer:

Integrity

Explanation:

In CAIN, integrity is realized through the use of message digest functions and hashes.

Integrity in CAIN simply means securing a message on transit without it being tampered. To accomplish and achieve integrity, hash functions are used. These hash functions receive arbitrary length message and bring out a fixed sized message digest.

The message digest and hash function maps input data of arbitrary length to an output fixed data length. Hashing is used to guarantee integrity.

5 0
4 years ago
Other questions:
  • Write a program having a concrete subclass that inherits three abstract methods from a superclass. Provide the following three i
    11·1 answer
  • Declare an array named scores of twenty-five elements of type int .
    7·1 answer
  • How to solve 3(x - 2) = 9x<br><img src="https://tex.z-dn.net/?f=3%28x%20-%202%29%20%3D%209x" id="TexFormula1" title="3(x - 2) =
    14·1 answer
  • What are ways to switch windows in Excel? Check all that apply. On the status bar, click the Windows button, and then click the
    9·1 answer
  • Choose the list of the best uses for word processing software.
    5·1 answer
  • Based upon the contents of the BOOKS table, which line of the following SQL statement contains an error?
    13·1 answer
  • You will be given a grocery list, followed by a sequence of items that have already been purchased. You are going to determine w
    7·1 answer
  • A crowd-funding open source business model, called _______, is where users offer money as a reward for new software or new featu
    8·1 answer
  • Most hard drives are divided into sectors of 512 bytes each. Our disk has a size of 16 GB. Fill in the blank to calculate how ma
    9·1 answer
  • Which document outlines the activities carried out during testing?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!