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

Determine 802.11a OFDM, 802.11a OFDM a) Orthogonal frequency-division m...

802.11a OFDM a) Orthogonal frequency-division multiplexing utilizing a 5-GHz band b) Same as FDM except all sub bands are used by only one source at a given time c)  Secu

List the advantages of arcnet, List the advantages of ARCNet. Here are ...

List the advantages of ARCNet. Here are some of the ARCNet's benefits: 1.  It is extremely reliable. 2. ARCNet is simple to install and troubleshoot. 3. It has an exce

Write your own http client to test your server, - The project should includ...

- The project should include a web server, and an example webpage - Webserver should continue to accept multiple requests from client browser - Webserver should print out logs: how

What is the mac address, The address for a device as it is recognized at th...

The address for a device as it is recognized at the Media Access Control (MAC) layer in the network architecture. MAC address is usually stored in ROM on the network adapter card a

Show the properties of microwaves, Q. Show the properties of Microwaves? ...

Q. Show the properties of Microwaves? Microwaves - Frequencies among 1 and 300 GHz - Unidirectional - Narrow focus requires sending as well as receiving antennas to

What is stop-and-wait protocol, What is Stop-and-Wait Protocol? In Stop...

What is Stop-and-Wait Protocol? In Stop and wait protocol, sender sends single frame, waits unless it receives confirmation from the receiver (okay to go ahead), and then sends

What are the two types of transmission technologies, What are the two types...

What are the two types of Transmission technologies, basis on which computer networks can be categorized? Broadly there are two types of transmission technology: 1. Broadc

What is the standard isdn term for a native isdn modem, TA is the standard...

TA is the standard ISDN term for a native ISDN modem

Explain about twisted-pair cable, Q. Explain about Twisted-Pair Cable? ...

Q. Explain about Twisted-Pair Cable? - Two conductors surrounded by insulating material - One wire utilize to carry signals and other used as a ground reference - Twistin

Sap is used by the cisco ios for which encapsulation types, "SAP" is used b...

"SAP" is used by the Cisco IOS for which encapsulation types? Ans) Three types:- Ethernet_802.2 Token-Ring FDDI_802.2

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