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 item is not part of a college application
olga_2 [115]

Answer:

Explanation:

application form and any fees

4 0
2 years ago
What is the different between 32bit anf 64 bit verision​
Elina [12.6K]

<u>The different between 32 bit and 64 bit version:​</u>

  • The main difference between 32-bit and 64-bit versions is that a 32-bit version can access 2^3^2 memory addresses which is roughly equivalent to 4 GB of memory.
  • On the other hand, a 64-bit version can access 2^6^4 memory addresses which equates to a huge amount of memory, 16 exabytes to be precise.  
  • Nowadays, we observe that almost all the computers have 64-bit processors, which means that they can access any amount of memory over 4 GB till 16 exabytes.
  • 64-bit processors have various advantages like the increased speed of operations, smooth multitasking and they can also support video games and software's that have high graphical requirements.
8 0
2 years ago
What are the functions of online gaming communities?
romanna [79]

Answer:

As a high-quality communication system, online games provide a virtual world where gamers communicate with each other by using rich interactive multimedia. This would facilitate communication among online gamers and enhance the development and maintenance of interpersonal relationships.

6 0
2 years ago
Why would Network Systems employees be employed by the government?
Ghella [55]
Well knowing how the government is with security id go with A. as it makes a lot of sense unlike B and D and if they were looking for software the question would mention it
8 0
3 years ago
Read 2 more answers
71 81 77 15 63 96 36 51 77 18 17
sp2606 [1]

Answer:

Following are the solution to this question:

Explanation:

This algorithm uses the divide and rule approach works, which splits the list into two sublists depending on if they are smaller or larger than the pivotal factor. It has O(n*log n) complexity.

It splits down the list in more than one version frequently till every sublist becomes based on a single element and fuses it to offer an ordered array. The merge type works according. It has O(n*log n) complexity.

Please find the attachment file of the sorting.

4 0
2 years ago
Other questions:
  • What task can a user accomplish by customizing theme colors?
    14·2 answers
  • What two images did you have to add to the wds server to handle the windows installation?
    7·1 answer
  • What is output by the following program? int i = 7; while (i&gt;=2){System.out.print (i +""); if ((i%3) == 0){ i +2; } else { i/
    6·1 answer
  • Almost immediately after a server migration project, employees are complaining that they can't reach the Internet. You sit down
    8·1 answer
  • In windows, a(n) ________ follows the file name and a period and indicates the file type.
    9·1 answer
  • Whic flag has a special role in debuging
    6·1 answer
  • Ciscon Telecom is a mobile operator in the European Union. The company provides personalized services to its customers, and its
    8·2 answers
  • According to the government, employees have a right to understand the risks associated with the materials they work with.
    15·1 answer
  • Design an if-then statement ( or a flowchart with a single alternative decision structure that assigns 20 to the variable y and
    5·1 answer
  • Kellyn needs to move Slide 8 of his presentation up so that it becomes Slide 6. What best describes how he can do this using the
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!