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
What tabs found in the Windows Task Manager dialog box
fredd [130]
The applications you have open, and some background processes.
7 0
3 years ago
For each problem listed below, use the drop-down menu to select the field of the professional who can help solve the issue.
Lapatulllka [165]

Answer:

An employee is having trouble opening a file on a computer.

  • → ✔ <u>information services and support</u>

The president of a company wants to give the company website a fresh new look.

  • → ✔ <u>interactive media</u>

An employee wants to work from home but can’t connect to the network from there.

  • → ✔ <u>network systems administration</u>

The vice president of sales would like help designing a new software program to keep track of sales.

  • → ✔<u> programming and software development</u>

<u>OAmalOHopeO</u>

5 0
2 years ago
Read 2 more answers
What is the computer’s natural language?
kirill [66]

Answer:

binary computer natural language

4 0
3 years ago
With working from home now becoming a norm what is an effective network for an organization to secure its internal resources acc
Umnica [9.8K]

Answer:

Always encrypt data never store anything in plain text someone could use wireshark to pull out a data packet and if the data is not encrypted, expect things to happen.

4 0
2 years ago
You can select a noncontiguous range of cells by pressing and holding the ________ key when using it in combination with other n
leonid [27]
Hey there!

I believe your answer will be the "Shift" key. You can hold down Shift and select a cell from your current cell position to select everything between the original position and the cell you clicked on without having to drag your mouse across the cells. If you were to hold down the Ctrl or Command key, you would only have your original selection and your new selection highlighted. 

Your answer will be Shift. 

Hope this helped you out! :-)
3 0
3 years ago
Other questions:
  • Gateway drugs are normally not addictive
    15·2 answers
  • Select the correct answer. Linda has written a program that works well on various operating systems, but she needs to increase t
    10·1 answer
  • Consider a system that uses a 32-bit unique salt where users have a 4-digit number as a password (e.g. 6813). Eve wants to crack
    8·2 answers
  • Describe and compare imperative (C), functional (SML) and logic (Prolog) programming paradigms.
    9·1 answer
  • Write and test a Python program to find and print the largest number in a set of real (floating point) numbers. The program shou
    5·1 answer
  • Which is the most popular language used in game programming?
    5·2 answers
  • Write down the stages in the information prcessing cycle in correct order​
    5·1 answer
  • In 200 words or more, please describe the Cyber Security Enhancement Act. Include when it was implemented and what it's purpose
    12·1 answer
  • The merge and center
    14·1 answer
  • What do you mean by HDML coding ​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!