Shared programming using library routines, Computer Networking

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.

Posted Date: 3/4/2013 5:16:53 AM | Location : United States







Related Discussions:- Shared programming using library routines, Assignment Help, Ask Question on Shared programming using library routines, Get Answer, Expert's Help, Shared programming using library routines Discussions

Write discussion on Shared programming using library routines
Your posts are moderated
Related Questions
Q. What do you mean by OpenMP? OpenMP is a compiler directive based standard developed in late 1990s together by a group of main computer software and hardware vendors. It is p

Shared variable programme structures  In this section, we talk about some more concepts related to the shared programme. Concept of Lock Locks are used for protected a

Output Port The function of the  port is  take  the packets that have  been stored in the out  put port  memory and transmits them over the out going  link. The queuing  and bu

Advantages of mobile wireless network over a wired network is it is very much popular, it is very easy to set up, it requires a simple plug and the speed and reliability is very

As discussed in the earlier section each computer linked to the Internet has a unique address. Let's assume your IP address is 1.2.3.4 & you wish to send a message to the computer

The major features of TCP are following: Reliability : TCP ensures that any data sent by a sender arrives at the destination as it was sent. There cannot be any data loss or mo

With a transaction server, the client requests remote procedures that reside on the server with an SQL database engine. These remote processes on the server execute a group of SQL

TCP/IP protocols are managed into five basic layers. Although some layers of the TCP/IP reference model related to layers of the ISO reference model, the ISO layers procedure does

Discuss the interdependence of networking hardware and software. Is it possible to have one without the other?

Q. Describe about Domain Name Space ? - Structure for systematize the name space in which names are defined in an inverted-tree structure with the root at the top - Every l