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
Which of the following is true about binary search. A. It uses binary numbers in its algorithm B. It is slower than sequential s
trapecia [35]

Answer:

<u> A. It uses binary numbers in its algorithm</u>

Explanation:

A Binary search is a type of algorithm designed to look through <em>only </em>a sorted array of data for a particular item.

It is<em> more efficient (faster) </em>than sequential search since the algorithm doesn't have to look up the entire array of data, but simply repeatedly divide in half the section of the array that could contain the searched item.

4 0
3 years ago
Traceability of requirements is helpful in the followingexcept
larisa86 [58]

Answer: D)  Identifying GUI's for a particular requirement

Explanation:

 Traceability of requirements is helpful except identifying GUI's for a particular requirements as, traceability in project management describe the relationships between two or more element throughout in the development process and outline the relationship between the customer requirement by traceability matrix. And the requirement of traceability is so important because it creating a downstream flow of software and test cases in software requirement but not helpful in GUI identification.

6 0
3 years ago
A cookie is.... a. an illegal use of information about a customer b. a feature of a Web site designed to attract children c. a f
Elodia [21]

Answer:

C. A file that a Web site stores on a visitor's computer

Explanation:

Have a nice day! :)

3 0
2 years ago
What is a number system, and what is the total number of digits used in this system called?
DENIUS [597]
The number system is what is use globally as are way of counting the total number of digits is 9 because you can make any number with characters 1-9
7 0
3 years ago
When editing the master slides, if you edit the layout on the title page, those changes appear on:
Fed [463]

D. only the first title slide in the presentation.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Use your own words to describe how IT/IS can support major functional areas in the business. Discuss at least two of these areas
    14·1 answer
  • Wich of these is an example of magnetic storage
    11·1 answer
  • The section called Breaking Substitution Ciphers (p. 166) describes a "random substitution cipher," in which each letter of the
    11·1 answer
  • The United States Army retains a history of all equipment acquisition from approval of requirements through funding, authorizing
    13·1 answer
  • The following relation schema can be used to register information on the repayments on micro loans.
    13·1 answer
  • A proper divisor of a positive integer $n$ is a positive integer $d &lt; n$ such that $d$ divides $n$ evenly, or alternatively i
    8·1 answer
  • I like the impact that the increasing number of social grants may have on the things mothers​
    14·1 answer
  • A variable is assigned a value on line 328 of a program. Which of the following must be true in order for the variable to work?
    12·2 answers
  • Write a description of the photograph to someone who cannot see the photograph. Be sure to include the title of the photograph a
    5·1 answer
  • Outside of a C program, a file is identified by its ________while inside a C program, a file is identified by a(n) ________. fil
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!