Shared programming using library routines, Computer Networking

Assignment Help:

Shared Programming Using Library Routines

The most well-liked of them is the use of combo function called fork() and join(). Fork() function is used to make a new child process. By calling join() function parent process waits the terminations of the child process to obtain the desired result.

Example 11: Consider the following set of statements

Process A                                 Process B

:                                                      :

fork B ;                                                      :

:                                                                :

join B;                                                      end B;

In the above set of statements process A makes a child process B by the statement fork B. Then A and B continue their computations independently up to  A reaches the join statement, At this stage, if B is already ended, then A continues implementing the next statement otherwise it waits for B to finish.

 In the shared memory model, a common trouble is to synchronize the processes. It may be possible that more than one process is trying to concurrently modify the similar variable. To solve this problem many synchronization mechanism like test_and_set, monitors and semaphores have been used. We shall not go into the details of these mechanisms. Quite, we shall represent them by a pair of two processes called lock and unlock. Whenever a process P locks a common variable, then only P can use that variable. Other simultaneous processes have to wait for the common variable until P calls the unlock on that variable. Let us see the effect of locking on the output of a program when we do not use lock and when we use lock.

Example 12

Let us write a pseudocode to find sum of the two functions f(A) + f(B). In the first algorithm we shall not use locking.

Process A                               Process B

sum = 0                                           :

:                                                  :

fork B                                    sum = sum+ f(B)

:                                                   :

sum = sum + f(A)                         end B

:

join B

:

end A

If process A implements the statement sum = sum + f (A) and writes the results into main memory followed by the computation of sum by process B, then we get the right result. But consider the case when B implements the statement sum = sum + f (B) before process A could write result into the main memory. Then the sum contains only f(B) which is not right. To avoid such inconsistencies, we use locking.

Process A                               Process B

sum = 0                                           :

:                                                  :

:                                                  lock sum

fork B                                    sum = sum + f(B)

:                                                   unlock sum

 lock sum                                        :

sum = sum + f(A)                         end B

unlock sum

:

join B

:

end A

In this case whenever a process gets the sum variable, it locks it so that no other process can access that variable which makes sure the consistency in results.


Related Discussions:- Shared programming using library routines

Exam, i have an exam i need it to be solved

i have an exam i need it to be solved

Explain about bridges, Bridges The bridge function is to attach separat...

Bridges The bridge function is to attach separate homogeneous networks. Bridges map the Ethernet address of the nodes residing on each network segment and allow only essential

Discuss about lan topologies, Discuss about LAN topologies LAN topolog...

Discuss about LAN topologies LAN topologies:   Network topology is a physical schematic that demonstrates interconnection of the many users. There are four fundamental topolog

Packet switches, PACKET SWITCHES:  To span large distances or several ...

PACKET SWITCHES:  To span large distances or several computers, networks must removed shared phase with packet switches. Each switch moves whole packet from one connection to

State the congestion avoidance process, State the congestion avoidance proc...

State the congestion avoidance process Notifies the source that congestion avoidance process should be initiated where applicable for traffic in the opposite direction of the r

Explain session layer in osi model, Q. Explain Session Layer in osi model? ...

Q. Explain Session Layer in osi model? - The session layer defines how to control, start and end conversations (called sessions) between applications. - This includes the c

Why you require connecting two computers for file sharing, You require conn...

You require connecting two computers for file sharing. Is it possible to do this without using a hub or router? Yes, you can connect two computers together using only one cable

Connection to packet switches, CONNECTION TO PACKET SWITCHES:  A packe...

CONNECTION TO PACKET SWITCHES:  A packet switch many join to devices and to other packet switches. But the speeds are different in both parts. There are typically high-speed j

What is meant by symmentric multiprocessing (smp), It treats all processors...

It treats all processors as equivalent. Any processor can do the work of any other processor. Applications are separated into threads that can run simultaneously on any available p

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd