Questions
hpw do a put the program to halt, placing a limit greater than 1 on the...

hpw do a put the program to halt, placing a limit greater than 1 on the eating state for each philosopher in the program below?







#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
#include <unistd.h>


#define N 5
#define THINKING 2
#define HUNGRY 1
#define EATING 0
#define LEFT (phnum + 4) % N
#define RIGHT (phnum + 1) % N
#define deprecated

int state[N];
int phil[N] = { 0, 1, 2, 3, 4 };

sem_t mutex;
sem_t S[N];

void test(int phnum)
{
if (state[phnum] == HUNGRY
&& state[LEFT] != EATING
&& state[RIGHT] != EATING) {
// state that eating
state[phnum] = EATING;

sleep(2);

printf("Philosopher %d takes fork %d and %d\n",
phnum + 1, LEFT + 1, phnum + 1);

printf("Philosopher %d is Eating\n", phnum + 1);

// sem_post(&S[phnum]) has no effect
// during takefork
// used to wake up hungry philosophers
// during putfork
sem_post(&S[phnum]);
}
}

// take up chopsticks
void take_fork(int phnum)
{

sem_wait(&mutex);

// state that hungry
state[phnum] = HUNGRY;

printf("Philosopher %d is Hungry\n", phnum + 1);

// eat if neighbours are not eating
test(phnum);

sem_post(&mutex);

// if unable to eat wait to be signalled
sem_wait(&S[phnum]);

sleep(1);
}

// put down chopsticks
void put_fork(int phnum)

{

sem_wait(&mutex);

// state that thinking

state[phnum] = THINKING;

printf("Philosopher %d putting fork %d and %d down\n",

phnum + 1, LEFT + 1, phnum + 1);

printf("Philosopher %d is thinking\n", phnum + 1);

if(phnum==N-1){ // this is the last philosopher for which we reverse the order of checking it will first check right then left

test(RIGHT);

test(LEFT);

}

else{ // this is for the remaining philosopher for which the order of checking will be first check left then right

test(LEFT);

test(RIGHT);

}

sem_post(&mutex);

}

void* philospher(void* num)
{

while (1) {

int* i = num;

sleep(1);

take_fork(*i);

sleep(0);

put_fork(*i);
}
}

int main()
{

int i;
pthread_t thread_id[N];

// initialize the semaphores
sem_init(&mutex, 0, 1);

for (i = 0; i < N; i++)

sem_init(&S[i], 0, 0);

for (i = 0; i < N; i++) {

// create philosopher processes
pthread_create(&thread_id[i], NULL,
philospher, &phil[i]);

printf("Philosopher %d is thinking\n", i + 1);
}

for (i = 0; i < N; i++)

pthread_join(thread_id[i], NULL);
}

In: Computer Science

1. Some students are more interested in the advertising component of marketing. Identify the factors that...

1. Some students are more interested in the advertising component of marketing. Identify the factors that make a television commercial memorable.  Identify five commercials.  We often remember commercials that we don’t like as well as the ones that we do like.  Who is the target market for each ad?  Identify why the ad was memorable. What advertising appeal was used?

2. Evaluate and compare the super bowl ads for the last two years (2018 & 2019). What ads were deemed the best?  Do you agree?  Did you see any differences in the ads from the two years? Did you identify any trends? Identify at least three ads that illustrate this trend.

In: Operations Management

If you needed to store facts about information that you were collecting, you would store these...

If you needed to store facts about information that you were collecting, you would store these facts in the ___.

What is hardware?

What replicates and spreads itself?

In: Operations Management

In previous weeks, we’ve talked a bit about the conceptual difference between the notion of a...

In previous weeks, we’ve talked a bit about the conceptual difference between the notion of a “residual” welfare state and an “institutional” welfare state. Explain what the difference is between these two models of the welfare state. What did the New Deal and its signature legislative achievements (think: the Social Security Act of 1935, the various work relief programs) represent in terms of how America’s approach to social welfare issues and policy was changing?

In: Psychology

What are the strengths of sequence diagrams? In your main post, select an appropriate scenario and...

What are the strengths of sequence diagrams? In your main post, select an appropriate scenario and identify why a sequence diagram can provide appropriate insight to solve the scenario. What are factors that would affect the workflow of the outlined sequence diagram to solve this given scenario? Please be sure to provide specific scenarios to address the strengths of sequence diagrams.

In: Computer Science

Using Perl create a program that will output the scores of 3 golfers that are playing...

Using Perl create a program that will output the scores of 3 golfers that are playing nine holes of golf.
Create a blank array, this will be a two-dimensional array
@golf_array;
Load up the follow scores
For hole 1: Golfer 1 shot 4, Golfer 2 shot 3, Golfer 3 shot 5
For hole 2: Golfer 1 shot 3, Golfer 2 shot 3, Golfer 3 shot 4
For hole 3: Golfer 1 shot 7, Golfer 2 shot 5, Golfer 3 shot 5
For hole 4: Golfer 1 shot 6, Golfer 2 shot 3, Golfer 3 shot 4
For hole 5: Golfer 1 shot 3, Golfer 2 shot 7, Golfer 3 shot 4
For hole 6: Golfer 1 shot 3, Golfer 2 shot 3, Golfer 3 shot 3
For hole 7: Golfer 1 shot 4, Golfer 2 shot 4, Golfer 3 shot 5
For hole 8: Golfer 1 shot 5, Golfer 2 shot 5, Golfer 3 shot 4
For hole 9: Golfer 1 shot 3, Golfer 2 shot 6, Golfer 3 shot 3
Print out the scores for each golfer
Golfer 1:
Hole 1 – 4
Hole 2 – 3

Hole 9 – 3
Golfer 2:
Hole 1 – 3
Hole 2 – 3

Extra credit:
Print out which golfer had the lowest score and what that score was.

In: Computer Science

You are given a sample of several compounds to separate by paper chromatography. You draw a...

You are given a sample of several compounds to separate by paper chromatography. You draw a pencil line exactly 1.0 cm from the bottom of the paper, and place a spot of sample on it. You dry the sample, then develop it in a solvent.

When the chromatogram is taken out of the solvent, the paper is wet up to 9.1 cm from the bottom of the sheet. The compound you are interested in shows up as a spot 7.1 cm from the bottom of the paper.

Calculate the following:

In the same time, how far did the solvent move?

What is the Rf factor for the compund?

In: Chemistry

This question is all about Java 1. If we need to import multiple classes from different...

This question is all about Java

1. If we need to import multiple classes from different packages do we need an import line for each? Why?

2. How does dot notation differ when invoking methods & importing packages?

3. How does * work when importing packages?

4. We have to import the Scanner class in order to use its methods. Why not for String or System or Math class?

5. What package are each of the classes found in?

6. We need an object to invoke (call) the String & Scanner methods. Why don't we need to instantiate an object to invoke the Math methods?

7. List the Math methods & their parameter

In: Computer Science

What is a content delivery network, and what are the advantages and disadvantages of using a...

What is a content delivery network, and what are the advantages and disadvantages of using a content delivery network. When do you think you should and should not use one, and why?

In: Computer Science

In Python. Create a function called predictKNN(). Your function will return the classification of your data-pointIn...

In Python. Create a function called predictKNN(). Your function will return the classification of your data-pointIn addition to any parameters you see fit, your function should accept:

  • k
  • a data-point: a vector of r numbers
  • a dataframe with r columns.
    Run your function at least 5 times with different parameters.

In: Computer Science

Implement a GUI for AVL Tree for int data type using JavaFX. The GUI should provide...

Implement a GUI for AVL Tree for int data type using JavaFX. The GUI should provide facility to add, remove and find data elements and also traversal (in-order, pre-order, post-order, level-order) of the tree structure. If tree become unbalance, it should display the message that tree become imbalanced. It should provide a button to make the tree a Balance Tree. Extra: It should provide the option to load the data from a file and save the data in a file. Make it interactive for deleting a node. It will show deletion, insertion and balancing operations in single stepping graphically.

In: Computer Science

Activity-Based Supplier Costing Clearsound uses Alpha Electronics and La Paz Company to buy two electronic components...

Activity-Based Supplier Costing

Clearsound uses Alpha Electronics and La Paz Company to buy two electronic components used in the manufacture of its cell phones: Component 125X and Component 30Y. Consider two activities: testing components and reordering components. After the two components are inserted, testing is done to ensure that the two components in the phones are working properly. Reordering occurs because one or both of the components have failed the test and it is necessary to replenish component inventories. Activity cost information and other data needed for supplier costing are as follows:

I. Activity Costs Caused by Suppliers (testing failures and reordering as a result)

Activity Costs    
Testing components $1,200,000
Reordering components 300,000

II. Supplier Data

Alpha Electronics La Paz Company
125X 30Y 125X 30Y
Unit purchase price $10 $26 $12 $28
Units purchased 120,000 73,900 15,000 15,000
Failed tests 1,600 780 10 10
Number of reorders 60 40 0 0

Required:

Determine the cost of each supplier by using ABC. Round Test and Reorder rates to the nearest dollar, and final answers to the nearest cent.

Alpha Electronics La Paz Company
125X 30Y 125X 30Y
Unit cost: $ $ $ $

In: Accounting

The Ste. Marie Division of Pacific Media Corporation just started operations. It purchased depreciable assets costing...

The Ste. Marie Division of Pacific Media Corporation just started operations. It purchased depreciable assets costing $47 million and having a four-year expected life, after which the assets can be salvaged for $9.4 million. In addition, the division has $47 million in assets that are not depreciable. After four years, the division will have $47 million available from these nondepreciable assets. This means that the division has invested $94 million in assets with a salvage value of $56.4 million. Annual depreciation is $9.4 million. Annual operating cash flows are $27 million. Depreciation is computed on a straight-line basis, recognizing the salvage values noted. Ignore taxes. Assume that the division uses beginning-of-year asset values in the denominator for computing ROI.

Required:

a. & b. Compute ROI, using net book value and gross book value. (Enter your answers as a percentage rounded to 1 decimal place (i.e., 32.1).)

ROI
Net Book Value Gross Book Value
Year 1    %    %
Year 2 % %
Year 3 % %
Year 4 % %

In: Accounting

As with all things, teachers and students may face challenges when utilizing assistive technology in the...

As with all things, teachers and students may face challenges when utilizing assistive technology in the classroom. Discuss challenges one might face when assistive technology is used, and how you as the teacher will handle such situations.

In: Psychology

Problem 4 • Use Java Collections to write a small program using NetBeans to do the...

Problem 4 •

Use Java Collections to write a small program using NetBeans to do the following:

1. Create a queue object of Integer items, myQueue.

2. Create a stack object of Integer items, myStack.

3. Enqueue the integers 10, 20. 30, .., 100 into myQueue, in that order.

4. Push the integers 10, 20, 30, ..., 100 into myStack, in that order.

5. Display the message: "Here are the elements of myQueue:".

6. Remove and display the front element of the queue until myQueue becomes empty.

7. Display the message: "And here are the elements of myStack:".

8. Remove and display the top element of the stack until myStack becomes empty.

In: Computer Science