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
A disadvantage of online surveys is that _________. a. it is difficult to access large numbers of potential respondents. b. they
Minchanka [31]

Answer:

B seems like the best answer to me.

Explanation:

7 0
4 years ago
The document asks about dependents because the number can
BARSIC [14]
The answer is: Lower overall taxes
8 0
3 years ago
Read 2 more answers
Compare and contrast traditional and cloud data backup methods. Assignment Requirements You are an experienced employee of the D
jasenka [17]

Answer:

Ensures all database elements are known and secured through inventory and security protocols. Catalogs databases, backups, users, and accesses as well as checks permissioning, data sovereignty, encryption, and security rules. 

Security Risk Scoring

Proprietary Risk Assessment relays the security posture of an organization's databases at-a-glance through risk scores.

 Operational Security

Discovers and mitigates internal and external threats in real time through Database Activity Monitoring plus alerting and reporting. Identifies and tracks behavior while looking for anomalous activity internally and externally.

Database Activity Monitoring

Monitors 1 to 1,000+ databases simultaneously, synthesizing internal and external activity into a unified console.

Only by covering both of these areas can organizations have defense in depth and effectively control risk.

8 0
3 years ago
10. Calculate the checksum for blocks of data with the following byte sum. (a) 1220 (b) 950​
OLga [1]

Answer:kalo gk salah yang

a

Explanation:

5 0
3 years ago
14.
pogonyaev
Answer is A : Cache memory
7 0
3 years ago
Other questions:
  • How do you calculate the total voltage in a series circuit with more than one component?
    13·2 answers
  • Suppose that some company has just sent your company a huge list of customers. You respond to that company with a strongly worde
    15·1 answer
  • Search engines enable you to
    9·2 answers
  • One of the network printers is producing copies where the toner is smeared on paper after printing. What component should be che
    11·1 answer
  • Physical activity such as sports or even a brisk walk can help reduce
    7·2 answers
  • A group of computers that are interconnected in order to share information or documents is called a
    13·1 answer
  • What is good prossesser
    15·2 answers
  • Points! taga pilipinas ba kayo?​
    10·1 answer
  • Question 13(Multiple Choice Worth 5 points)
    6·1 answer
  • What are web protocols.
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!