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:
Runa, because she’s like me I r l lol
Explanation:
A program that repeatedly prompts a user for integer numbers :
biggest = none
smallest = none
while True:
input = raw_input(“Enter a number:”)
if(input == “done” break
try:
number = float(inp)
except ValueError:
print “Please enter only numbers”
else
if smallest is None:
smallest = number;
biggest = number;
elif number < smallest:
smallest = number
elif num > largest:
largest = number
Print “Greatest is “, biggest
Print “Smallest is”, smallest
In this program an input is obtained, if it is equal to the word “done”, then the program stops b printing greatest and smallest number in the given input.
If invalid inputs are given then user is prompted to enter valid number. Otherwise the value of smallest and greatest are calculated according to the input using if-else construct.
Answer: Applications for desktop or laptop computers are sometimes called desktop applications, while those for mobile devices are called mobile apps. When you open an application, it runs inside the operating system until you close it
Explanation:
By Pelago, INC. Founders of Pelago are: Jeff Holden<span> and </span><span>Darren Vengroff.</span>