Question

In: Computer Science

4. PROPOSED SOLUTION (PSEUDOCODE) • Start. • Initialize the clear cycle=1 and part[2],generated=0. • Declare the...

4. PROPOSED SOLUTION (PSEUDOCODE)
• Start.
• Initialize the clear cycle=1 and part[2],generated=0.
• Declare the parts of the car as ‘engine’, ‘chassis’, ‘ss’.
• Initialize the semaphore sem t ready.
• Assign the ids from 0 to 3.
• Declare the function void * gen branch(void*arg) which generates the assembly
branch.
• In the above function declare i,j,k=0 .
• Repeat the step 7 until while(1).
• Declare sleep(1) so that when the loop runs the next time it puts threads to sleep for
1 sec.
• Declare sem wait( ) which will decrement the value pointed by the semaphore when
greater than zero.
• So, sem wait(&ready) and if (clear cycle= =1) then
• i=k, increment the value of i by 1 and assign it to j.
• Assign k=j.
• Declare sem post( ) which increments the value pointed by the semaphore.
• Print “ Parts are being moved”.
• Declare the function void*assembly(void*arg) which does the assembly in
assembly branch.
• In the above function declare flag=1.
• Repeat the step 16 until while(1).
• Check if the generated branch is not the any two other branches.
• Print “ Branch has completed the assembly”.
• Check if clear cycle==1 and flag= = 0 then print “ THE CYCLE IS COMPLETE”.
• Declare sem init(&ready,0,1) which will initialize the unnamed semaphore.
• Return 0 and stop.

please tell me the name of this algorithm

please tell me the name of the given above one.

Solutions

Expert Solution

The Above Pseudocode is the Algorithm of Semaphores in Operating Sytem in which particularly Binary semaphore algorithm (also called Mutex)

What is Semaphore ?

Semaphore is an simple variable algorithm which is used to solve critical section problems also called "Mutual Exclusion" and achieve the process synchronization in the "Multiprocessing Environment ". Multiprocessing Environment is an environment where we can perform multiple process in same time to utilize our "CPU" time properly which is most important in modern world of computers our work to be done in an efficient way.

"Critical Section Problem" which is know as there are some resources like "Registers" and "RAM" in our computer, These are important components for the process to be done for us in an efficient way.These components are expensive in cost and other features. So they are limited in our computers, so we need to use them properly to achieve Multiprocessing in our computer. Assume that there is program has executing in particular time, In Process(Execution of program) it need one resource which is like variable which holds the particular memory location for other part of program, so our computer make the "Variable" as a "Critical Section" (Where only process can be executed in particular time ) and use the Resource efficiently to execute the program.

Properties of Semaphores are

  1. It's simple and always have a non-negative Integer value.
  2. Works with many processes.
  3. Can have many different critical sections with different semaphores.
  4. Each critical section has unique access semaphores.
  5. Can permit multiple processes into the critical section at once, if desirable.

To achieve Multiprocessing by the Critical Section we use Algorithms like Semaphores and Monitors.

Semaphores are two types Binary Semaphore and Counting Semaphore. This Semaphores has two functions like SemWait and SemIncrement

** In the above Pesudocode we use Binary Semaphore which is also called Mutex to achieve process synchronization in multiprocessing with SemWait and SemPost(SemIncrement) functions to achieve critical section Which is the Generating Car By using Car parts.

Small Description about Functions in above code are

In lines 1 to 3 we are declaring the required variables to generate a car in line we are initializing Semaphores 0 to 3 with "Sem t " ready function which is the function where the process start and cycle to check one car is completely generated or not.

And Sem Wait() function in line 10 where the process is in waiting position where other process(one car is being generated)

And SemPost() function in line 14 where the process of generating the car by using the car parts (Resources ) is being done

Function void * gen Branch function to create sub process in the program to create cycle of generating car.

Function void * gen Assembly function in the critical section which is the one which assembles the car parts and make cycle complete when the cycle is complete Check if clear cycle==1 and flag= = 0 then print “ THE CYCLE IS COMPLETE”. is being executed and make other semaphore init ready function to perform another cycle of car assembly will be done.

This process is done by using the same resources for particular time to generate desired output for the customer. This is called process synchronization.


Related Solutions

A= 1 2 4 0 1 -2 -1 0 1 2 0 3 8 1 4...
A= 1 2 4 0 1 -2 -1 0 1 2 0 3 8 1 4 . Let W denote the row space for A. (a) Find an orthonormal basis for W and for W⊥. (b) Compute projW⊥(1 1 1 1 1 ).
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)MEAN – B.)MEDIAN - C.)MODE - D.)STANDARD DEVIATION – E.)5 NUMBER SUMMARY – F.)BOX AND WHISKERS PLOT – G.) OUTLIERS-
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)5 NUMBER SUMMARY – B.)BOX AND WHISKERS PLOT – C.) OUTLIERS-
Part I: Numerical Integration Evaluate the following integrals: i. ∫4(1−?−4?3 +2?5)?? 0 ii. ∫3(?2??)?? 0 a)...
Part I: Numerical Integration Evaluate the following integrals: i. ∫4(1−?−4?3 +2?5)?? 0 ii. ∫3(?2??)?? 0 a) Analytically b) Multiple application of Trapezoidal rule n = 4. c) Simpson’s 1/3 rule for n = 4. d) Simpson’s 1/3 and Simpson’s 3/8 rule for n = 5. e) Determine the true percent relative error.
Part 1. Describe the boundaries of the triangle with vertices (0, 0), (2, 0), and (2,...
Part 1. Describe the boundaries of the triangle with vertices (0, 0), (2, 0), and (2, 6). (a) Describe the boundary with the top function, bottom function, left point, and right point. (b) Describe the boundary with the left function, right function, bottom point, and top point. Part 2. Consider the triangle with vertices (0, 0), (3, 0) and (6, 6). This triangle can be described using only one of the two perspectives presented above: top-bottom or left-right. Explain which...
The Product Life Cycle Part & The New Product Process 4 stages are 1. introduction 2....
The Product Life Cycle Part & The New Product Process 4 stages are 1. introduction 2. growth 3. maturity 4. decline Assess the value of the product life cycle as a tool for product succession planning and related product management activities. Give your opinion on whether or not the Product Life Cycle can help health care managers in promoting portfolio planning, strategy formulation, and forecasting. Provide one (1) example to support your rationale. Select two (2) stages of the Product...
4. Given Pseudocode: Algorithm3(n): y = 0 for i = 1 to n do y =...
4. Given Pseudocode: Algorithm3(n): y = 0 for i = 1 to n do y = 1 while y < i2 do y=2y return y a. What's the output of Algorithm3(n) as a function of n? b. What's the running time of Algorithm3(n) as a function of n? Represent this as a summation. c. Prove the running time to be O(n log n).
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6...
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6 1 5 6 8 2 4 6 7 3 4 5 9 10 5 8 9 4 7 9 6 7 8 6 How can I detect when 'cin' starts reading from a new line. The amount of numbers in each row is unknown. I need them in type 'int' to use the data.
Part B : Answer any 4 of the following questions. Exercise 1 - A firm generated...
Part B : Answer any 4 of the following questions. Exercise 1 - A firm generated net income of $862. The depreciation expense was $47 and dividends were paid in the amount of $25. Accounts payables decreased by $13, accounts receivables increased by $28, inventory decreased by $14, and net fixed assets decreased by $8. There was no interest expense. What is the net cash flow from operating activity? Explain the usefulness of the net cash flow from operating activities...
1. Use the Laplace transform to solve the initial value problem. ?"+4?′+3?=1−?(?−2)−?(?−4)+?(?−6), ?(0)=0, ?′(0)=0 2. Use...
1. Use the Laplace transform to solve the initial value problem. ?"+4?′+3?=1−?(?−2)−?(?−4)+?(?−6), ?(0)=0, ?′(0)=0 2. Use the Laplace transform to solve the initial value problem. ?"+4?=?(?), ?(0)=1, ?′(0)=−1     = { 1, ? < 1 where ?(?) =   {0, ? > 1.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT