Unformatted text preview:

Process is the activity of executing a program in CPU. A program that is alive. Conceptually, each process has its own CPU.All processes, if possible, run concurrently. Physical concurrency = Parallelism: Requires multi CPULogical concurrency = time-shared CPUProcesses compete or cooperate. Example. A program makes a call r = f(x).What if it doesn’t want to wait till the result r is returned?Want to be able to do this:■ r = f(x) ■ do something else while the function isn’t returned■ use intermediate results; wait if f(x) is not complete.These all amount to: ■ Make the function call and then do the other works while the function call is still pending (process)■ Retrieving values from processes and functions executingindependently the rest of the process (communication)■ Waiting for things to complete (synchronization)Conway’s model for parent-child processes:The Petri-netdisplays parallel (asynchronous) processes in actions. Sometimes, cobegin-coend construct features wellA;cobeginB; C;coend;D;Conway suggests a more general model: A; L: C;fork(L); join(X);B;await-join(X);D;The “join” synchronizes the two processes and then kills one. Only then the remaining process proceeds to D. ●ACBDIn UNIX, Conway’s model is somewhat preserved. A;if (fork() = = 0) {B; // child processexit();}else {C; // parent processWait(); //wait till B calls exit }D; // parent processIn UNIX, ……pid = fork (); // creates a child with a pid = 0 // parent process receives the pid of the childNote. fork() function is expensive in set-up time and memory. Alternatively, a thread construct is desired. This isalso known as a light-weight process. A thread is a schedulable part of a process. Multithreaded operations using Pthread library in C is oftenused to generate and work with thread. But this library is not thread-safe (no guarantee that concurrent threads will work properly).Java language supports threads as one of its essential features. Java library provides a Thread class that is rich in collections. Example. public class HelloThread extends Thread { public void run() { System.out.println("Hello from a thread!"); } public static void main(String args[]) { (new HelloThread()).start(); }} Thread.start starts a new thread. A Model of concurrent processes(From Operating Systems Theory by Coffman & Denning)Central commodity is a task T. Initiation of task T is the event Tand the termination is the event T(.)t time occurrence of an event.The duration of a task T is )T(t)T(t  and is assumed non-zero.Our tasks are uninterpreted. A set of n tasks comprises a task-set: ]T,...,T,T[n21 under a partial-order. The pair),(C  is a task-system.TT means T is completed before Tis allowed to begin. A task-system Cis independent if   Tasks are performed on a physical system comprising a number of resources. Collectively, these resources describe the system state Ss . The function of tasks is to promote and migrate the system from allowed state to state)Ss,s(ss .Task initiation events correspond to: a. Acquisition or assignment of resourcesb. Initialization of resource statesc. Reading input valuesTask termination events correspond toa. Release of resourcesb. Writing of output valuesc. Saving resource states, etc. Graphical representation of a task system is a precedence graph with its vertices over and edges)T,T( if only if TTand there exists no Tsuch that TTT. A typical example:Some observations:a. A task with no successor is a terminal taskb. A task with no predecessor is an initial taskc. If a task is neither a successor nor a predecessor to any task is an independent taskd. T,Tare concurrent if they are independent to each other.e. A nonterminal task is at a level k in C if the shortest path from the initial task to this vertex is of length k.An execution sequence  in an n-task system ),(C  is any string n221a...aa where each ia is either an initiation event or a termination event subject to the following conditions:a. Each Tand T of T will appear only once in .1T2T3T4T5T6Tb. if Tai then at some 1ik  Takc. if Tai then at some ik  Takd. In , no unmatched initiation/termination event will appear on its own.Some valid sequences for our graph:1665544332211TTTTTTTTTTTT6624554332112TTTTTTTTTTTTA task Tis live in an execution sequence i21a...aa if for some Taj where ij  is invoked but its termination Takis yet to be posted where ik .A partial execution sequence is a prefix of an execution sequence. A thread is a partial execution sequence where every initiation action is matched with its termination, and every termination action is preceded by an initiation action. At theconclusion of a thread, there is no live task lingering.A typical thread is supported by dummy actions, if necessary. For instance, dummydummythreadTˆT is a valid string. Atask-system is closed if it is bracketed bya starting and an ending task. We’d be dealing with closed systems.As a task sequence  unfolds over resource set  the system migrates from state to state yielding a string of states starting the initial state 0s. If  then n2i10s...s...ss where each ia transforms the system i1iss . Sometimes, i1iss  if ia is only a trivial action like reading a memory location.Suppose, 1C and 2Care closed task systems with no tasks incommon. a. 21C.C is a concatenation of the task systems, the end task of 1C now precedes the first task of 2C.b. 21C||CC  is a parallel system such that if )nm(221c..ccc is inC and then )CC( ,21with m221a..aa and n221b...bb such thatstartT2T3T4T5TendT■ 1c is either 1a or 1b■ i21a...aa and j21b...bb are the elements of ji21c...cc and )nm(2ji , then 1jic is either 1ia or 1jb. c. ...C.C.C.CCk is a k-fold looping system when the task sequence C repeats k-times. At a programming level, following models are encouraged:For asynchronous (potentially parallel) construct involving independent processes 21C||C :: cobegin1C;2C;coend;This is also abstracted as a parallel construct)C,C(P21 Compare this to the sequential (concatenated) construct.21C.C = )C,C(S21:: 21C;CExcept


View Full Document

SUNY Poly CS 521 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?