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.
Answer:
Explanation:
Disposed of in a contained way/recycled.
<u>Answer:</u>
<em>A prototype for a function called isPrime that returns is true.</em>
<u>Explanation:</u>
Function prototype is just a skeletal part of the function which has <em>a return type, function name and the respective parameters. </em>
There is a difference between function and function prototype.
Function is nothing but a <em>function definition</em>, where it actually has all the lines of codes which need to be processed when it is called. It can be invoked any number of times and anywhere within the<em> scope of the function</em>. <em> </em>
As per the given question, the prototype can be,
<em>bool isPrime (int);
</em>
The CPU is the most important. It is the brains of the Computer.
Motherboard
-------------------------------