Thread algebra for poly-threading

Threads as considered in basic thread algebra are primarily looked upon as behaviours exhibited by sequential programs on execution. It is a fact of life that sequential programs are often fragmented. Consequently, fragmented program behaviours are f…

Authors: J. A. Bergstra, C. A. Middelburg

Thread Algebra for P oly-Threading ⋆ J.A. Bergstra and C.A. Middelburg Programming Researc h Gro up, Univ ersit y of Amsterd am, Kruislaan 403, 1098 SJ A msterdam, the N et h erlands J.A.Bergst ra@uva.nl ,C.A.Midd elburg@uva.nl Abstract. Threads as considered in b asic thread algebra are primarily looked up on as b ehaviours exhibited by sequ entia l programs on execu- tion. It is a fact of life th at sequ ential programs are often fragmented. Consequently , fragmented program beh a viours are frequ ently fo und. I n this pap er, w e consider this ph enomenon. W e extend basic thread al- gebra with the barest mec hanism for sequencing of threads that are taken fo r fragments. This mechanism, called p oly- threading, supp orts b oth autonomous and non-auton omous thread selection in sequen cing. W e relate the resulting th eory to the algebraic theory o f pro cesses known as A CP and use it to describe analytic execution arc h itectures suited for fragmen t ed programs. W e also consider the case w here the s teps of fragmented program b ehaviours are interlea ved in th e wa ys of non- distributed and distributed multi-threading. Keywo rds: p oly- threading, thread algebra, process algebra, execu t ion ar- chitecture, non-distributed multi-threading, distributed m ulti-t h reading. 1998 ACM Computing Classification: D.4.1, F.1.1, F.1.2, F.3.2. 1 In tro duction In [11], we considere d fra gmentation of sequential programs that take the form of instruction sequences in the setting o f program algebra [4 ]. The ob jective of the current pa pe r is to develop a theory of the behaviours exhibited by sequential progra ms on execution that cov ers the case where the progra ms ha v e b een split int o fragments. It is a fa c t of life that sequential progr a ms are often fragmented. W e remar k that an impo rtant reason for fragmentation of progr ams is that the exec ution a rchitecture a t ha nd to ex ecute them sets b ounds to the size of progra ms. How ever, there may also b e other r easons for pro gram frag ment ation, for instance business economical reasons. In [4], a start was made with a line of resear ch in whic h sequential pr ogra ms that tak e the form of instruction sequences and the b e haviours exhibited b y se- quential progr ams on execution are inv estig ated (see e .g. [3, 7, 18]). In this line of resear ch, the view is taken tha t the b ehaviour exhibited by a sequential pro gram ⋆ This researc h has been p artly carried out in the framew ork of the Jacquard- p ro ject Symbiosis , which is funded by the N etherlands Organisation for Scientific Research (NWO). on execution takes the form of a thre ad as consider ed in basic thread algebr a [4]. 1 With the curr ent pap er, we ca rry on this line of rese a rch. Therefor e, we co nsider progra m frag ment behaviours th at take the form of threads a s considered in basic thread algebra. W e extend basic thread algebra with the barest mechanism for sequencing of threads that ar e taken for prog ram fr a gment b ehaviours. This mechanism is c a lled p oly-thr e ading. Inhere nt in the b ehaviour exhibited b y a program on execution is that it do es certain s teps for the purpos e of interacting with some service provided by an execution en vironment. In the setting of thread a lg ebra, the use mechanism is intro duced in [8] to a llow for this k ind of interaction. Poly- threading supp o rts the initialization of one o f the ser vices us e d every time a thread is started up. With p oly-threa ding, a thread s election is made whenever a thread ends up with the inten t to achiev e the start-up of another thread. That thread selection can b e made in tw o wa y s : b y the terminating thread o r externally . W e show how thread selections of the latter kind ca n b e internalized. Both thread and service lo ok to be sp ecial cases of a more genera l no tion of proc e ss. Ther efore, it is interesting to know how thre a ds a nd services a s con- sidered in the extens io n of basic thread algebr a with p oly-threa ding relate to pro cesses as c o nsidered in theor ies a bo ut concurrent pr o cesses such as ACP [1], CCS [17] and CSP [16]. W e sho w that threads and se r vices as consider ed in the extension of basic threa d a lgebra with p o ly -threading can be viewed a s pro cesses that are definable o ver the extension of A CP with conditions introduced in [5]. An analytic exe c ution architecture is a mo del of a hypo thetica l execution en- vironment for sequential progra ms that is designed for the pur po se of explaining how a prog ram ma y be exe c uted. The notion of analytic execution architecture defined in [1 2] is suited to sequential progr ams that hav e not b een split into fragments. W e use the e x tension of bas ic thread alg ebra with p oly-thre a ding to describ e analytic execution a rchitectures suited to sequential prog rams that hav e bee n s plit into fragments. In systems resulting from con tempo rary progra mming, we find distributed m ulti-threading and threa ds that a re pr ogra m fragment b ehaviours. F or that reason, it is in teresting to com bine the theory of distributed strategic in terleaving developed in [9] with the extension of basic threa d alg ebra with poly- threading. W e take up the co mbination b y introducing t w o p oly-thr e a ding cov ering v aria- tions of the simplest form of interleaving for distributed m ulti-threading consid- ered in [9]. The line of re search car ried on in this pap er has two main themes: the theme of instruction s equences and the theme of threads. Bo th [11] and the c urrent pap er a r e concerned with pr ogram fragmentation, but [1 1 ] elab or ates on the theme of instruction sequences and the curr ent pap e r elab ora tes on the theme of threads. It happ ens that ther e a re asp ects of prog ram fra g mentation that ca n be dealt with at the level o f instruction seq uences, but ca nnot b e dealt with at 1 In [4], basic thread algebra is in trod uced under the name basic polarized process algebra. Prompted by the developmen t of thread algebra [8], which is a design on top of it, basic p olarized process alge bra has b een renamed to basic thread algebra. 2 the level o f threads. In pa rticular, the ability to replace sp ecial instructio ns in an instruction sequence fragment by different o rdinary instructions ev ery time execution is switc hed over to that fragment ca nno t be dealt with a t the lev el o f threads. Thr eads, which are int ended for e x plaining the mea ning of sequen tial progra ms, turn out to b e to o abstract to de a l with prog r am fra g mentation in full. This pap er is organized as follows. First, we revie w bas ic thread algebra and the use mechanism (Sections 2 and 3). Next, we extend basic thread algebra with po ly-threading a nd show how external thread selections in p oly-threading can b e int ernalized (Sectio ns 4 and 5). F ollo wing this, we revie w A CP with co nditions and rela te the extension of ba s ic threa d algebr a with p oly-threading to ACP with conditio ns (Sections 6 and 7). Then, w e discuss a nalytic execution a rchi- tectures s uited for prog rams that hav e b een fragmented (Section 8). After that, we introduce for ms of interleaving suited for non-distr ibuted and distributed m ulti-threading that cov er p oly-thr eading (Sections 9, 10 and 11). Finally , we make some concluding remark s (Section 1 2). Up to and including Section 8 , this paper is a revision of [10 ]. In that pape r, the term “ sequential p oly-thr eading” stands for “po ly -threading in a setting where multi-threading or any o ther form o f concurre ncy is absent”. W e conclude in hindsigh t tha t the use of this term is unfortunate and do not use it in the current pap er . 2 Basic Thread Algebra In this section, we review BT A, a fo rm of pro cess algebr a which is tailored to the description of the b ehaviour o f deterministic sequential progr ams under execution. The behaviours concerned are called thr e ads . In BT A, it is assumed that there is a fixed but arbitrary finite set of b asic actions A with tau 6∈ A . W e wr ite A tau for A ∪ { tau } . The members of A tau are referred to as actions . The intuition is that eac h ba s ic action p erfo rmed b y a threa d is taken as a command to b e pro cessed by a service provided by the exec utio n environmen t of the thre a d. The pro cessing o f a command ma y inv o lve a change of state of the service concerned. At completion of the pro cessing of the command, the service pro duces a reply v alue. This r eply is either T or F and is returned to the thread concerned. Although BT A is one-so rted, w e ma ke this so rt explicit. The reaso n for this is that w e will extend BT A with additional sorts in Sections 3 and 4 . The algebr a ic theory BT A has one sor t: the sor t T of t hr e ads . T o build terms of sort T , B T A has the follo wing constants a nd op erators : – the de ad lo ck constant D : T ; – the termination constant S : T ; – for each a ∈ A tau , the p ostc onditional c omp osition op era tor E a D : T × T → T . 3 T able 1. Axiom of BT A x E tau D y = x E tau D x T1 T able 2. Axioms for guarded recursion h X | E i = h t X | E i if X = t X ∈ E RDP E ⇒ X = h X | E i if X ∈ V( E ) RSP T erms of sor t T are built a s usual (see e.g. [19 , 20]). Througho ut the paper , we assume that there are infinitely man y v ariables of sort T , including x, y, z . W e in troduce action pr efi xing as an abbreviation: a ◦ p , where p is a term of sort T , abbreviates p E a D p . Let p and q b e clo s ed terms o f so rt T and a ∈ A tau . Then p E a D q will per form action a , a nd after that pro ceed as p if the pro cessing of a leads to the reply T (called a positive reply), and pro ceed as q if the pr o cessing of a lea ds to the re ply F (called a negative r eply). The a ction tau plays a sp e c ial ro le. It is a conc r ete internal action: performing tau will nev e r lead to a state c hange and alwa ys lea d to a p ositive reply , but notwithstanding all that its presence matters. BT A has only one axiom. This axio m is given in T a ble 1 . Using the a bbrevia- tion intro duced a bove, ax iom T1 ca n b e written as follows: x E tau D y = tau ◦ x . Each clo sed BT A term of s ort T deno tes a finite thread, i.e. a thread o f which the length of the sequences of actions that it can p erfo r m is bounded. Guar ded recursive sp ecifica tio ns give rise to infinite threads. A guar de d re cursive sp e cific ation over BT A is a set of recursio n equations E = { X = t X | X ∈ V } , where V is a set of v a r iables of so rt T and each t X is a term of the form D , S or t E a D t ′ with t and t ′ BT A terms of sort T that contain only v ar iables from V . W e write V( E ) for the set of all v ar iables that o ccur on the left-hand side of a n eq ua tion in E . W e are only interested in mo dels of BT A in which g uarded rec ursive sp ecifications ha v e unique so lutions, such as the pro jective limit mo del o f BT A pres ent ed in [2]. A thread that is the solution of a finite gua rded recursive specifica tion ov er BT A is called a finite-st ate threa d. W e extend BT A with guarded r ecursion by adding constants for so lutions of guarded recursive sp ecifica tions and axioms concerning these additional con- stants. F o r each guarded r ecursive sp ecifica tion E and each X ∈ V( E ), we add a constant of sort T standing for the unique solution of E for X to the constan ts of BT A. The consta nt standing for the unique s olution of E fo r X is denoted by h X | E i . Moreover, we add the axioms for guarded rec ur sion given in T able 2 to BT A, where we write h t X | E i for t X with, for all Y ∈ V( E ), all o ccur rences of Y in t X replaced b y h Y | E i . In this table, X , t X and E sta nd for an arbitr ary v ariable of sort T , an a rbitrary BT A term of sort T and an a rbitrar y guarded recursive sp ecification ov er BT A, resp ectively . Side conditions are added to r e- strict the v a r iables, terms and guarded recur sive sp ecifications for which X , t X and E stand. 4 W e will wr ite BT A+REC for BT A ex tended with the constants for solutio ns of guarded recursive sp ecifications and axioms RDP and RSP . 3 In teraction of Threads with Services A thread may perfor m certain basic actions o nly for the sake of ha ving itself affected by some service. When pro cessing a bas ic action p erformed by a thread, a s e r vice affects that thread by re tur ning a reply v a lue to the thread at comple- tion of the pro cessing o f the basic action. In this se ction, w e introduce the use mechanism, whic h is co ncerned with this kind of interaction b etw ee n threads and services. 2 It is assumed tha t there is a fixed but ar bitrary finite set F of fo ci and a fixe d but arbitra ry finite set M of met ho ds . Each fo cus pla ys the role of a name of a service pr ovided by the ex ecution environment that can b e requested to pr o cess a command. Each metho d pla ys the role of a command proper . F or the set A of basic actions, w e take the set { f .m | f ∈ F , m ∈ M} . A thread p erforming a basic action f .m is co nsidered to make a request to a ser vice that is kno wn to the thread under the name f to pro cess c ommand m . W e in tro duce y et another sort: the so rt S of servic es . Ho wever, w e will not int ro duce constan ts and o p e rators to build terms of this sort. S is considered to stand for the set of all services. W e ident ify ser vices with functions H : M + → { T , F , B } that satisfy the following condition: ∀ ρ ∈ M + , m ∈ M • ( H ( ρ ) = B ⇒ H ( ρ y h m i ) = B ) . 3 W e write S for the set of a ll s e r vices and R for the set { T , F , B } . Given a ser v ice H a nd a method m ∈ M , the derive d servic e of H after pro cessing m , written ∂ ∂ m H , is defined b y ∂ ∂ m H ( ρ ) = H ( h m i y ρ ). A service H ca n be under sto o d as follo ws: – if H ( h m i ) 6 = B , then the req uest to pro cess m is a ccepted by the ser vice, the reply is H ( h m i ), and the service pr o ceeds as ∂ ∂ m H ; – if H ( h m i ) = B , then the r e quest to pro cess m is not accepted by the ser v ice. F or ea ch f ∈ F , we introduce the u se o p erator / f : T × S → T . Intu itively , p / f H is the thread tha t results from proces sing a ll basic actions per formed b y thread p that a re o f the for m f .m by serv ic e H . When a ba sic a c tion of the form f .m p erfor med by thread p is pro ce ssed by servic e H , it is turned into the in ternal action tau and pos tconditional comp osition is remov ed in fav our of action prefixing on the basis o f the reply v a lue produce d. The ax ioms for the use opera tors are giv en in T able 3. In this table, f a nd g 2 This versio n of the use mechanism was first in trodu ced in [8]. In later pap ers, it is also called thread-service composition. 3 W e write D ∗ for the set of all finite sequences with elemen ts from set D and D + for the set of all non-emp ty fin ite seq u ences with elements from set D . W e use the follo wing notation fo r fin ite sequences: h i for the empt y sequence, h d i fo r the sequence having d as sole element, σ y σ ′ for th e concatenation of finite sequences σ and σ ′ , and len( σ ) for the length of fi nite sequence σ . 5 T able 3. Axioms for u se S / f H = S TSU1 D / f H = D TSU2 tau ◦ x / f H = tau ◦ ( x / f H ) TSU3 ( x E g .m D y ) / f H = ( x / f H ) E g .m D ( y / f H ) if ¬ f = g TSU4 ( x E f .m D y ) / f H = tau ◦ ( x / f ∂ ∂ m H ) if H ( h m i ) = T TSU5 ( x E f .m D y ) / f H = tau ◦ ( y / f ∂ ∂ m H ) if H ( h m i ) = F TSU6 ( x E f .m D y ) / f H = D if H ( h m i ) = B TSU 7 stand for ar bitrary fo c i from F and m stands for an arbitrar y metho d from M . Axioms TSU3 and TSU4 express that the action tau and ba sic actions of the form g .m with f 6 = g are not proc essed. Axioms TSU5 and TSU6 express that a thread is affected by a s ervice a s describ ed ab ov e when a basic action o f the for m f .m p erfor med by the thread is pro cess ed by the s ervice. Axio m TSU7 ex presses that deadlo ck takes plac e when a basic action to be pr o cessed is not a ccepted. Let T stand for either BT A o r BT A+REC. Then we will write T +TSU for T , tak ing the set { f .m | f ∈ F , m ∈ M} for A , extended with the use op e r ators and the axioms from T able 3. 4 P oly-Threading BT A is a theory of the b ehaviours exhibited by sequential prog rams on e x ecution. T o cover the ca se where the pro grams hav e b een split into fragments, we extend BT A in this sectio n with the barest mec hanism for seq ue ncing of thr eads that are taken for fragments. The resulting theory is called T A pt . Our g eneral view on the way of a chieving a joint b ehaviour of the program fragments in a collection of program fragments b etw een whic h ex ecution ca n b e switched is as follows: – there can only be a single progra m fra g ment b eing executed at an y s tage; – the progr am frag ment in question may make a ny progr a m frag ment in the collection the one being executed; – making another pr ogra m fragment the o ne b eing executed is effected by executing a sp ecial instruction for switc hing ov er execution; – any prog r am fragmen t can b e taken fo r the one b eing executed initially . In o r der to obtain such a joint behaviour fr om the behaviours of the progr a m fragments on exec ution, a mechanism is needed by which the start-up o f a n- other progra m frag ment b e haviour is effectuated whenever a pr ogram fragment behaviour ends up with the inten t to achiev e such a start-up. In the se tting of BT A, taking threads for prog ram fra gment b ehaviours, this requires the in tr o- duction of an additional sort, additional co nstants and additional op e rators . In doing so it is s uppo sed that a collection of threa ds that corr esp onds to a collec- tion of progra m fragments b etw een which execution can be switc hed takes the form of a sequence, c a lled a thread v ector. 6 Like in BT A+ TSU, it is a ssumed tha t there is a fixed but a rbitrar y finite set F of foci and a fixed but arbitrary finite set M of metho ds. It is also assumed that tls ∈ F a nd init ∈ M . The fo c us tls and the metho d init play sp ecial r o les: tls is the fo cus of a s ervice that is initialized each time a thread is sta r ted up by the mechanism refer red to ab ov e and init is the initialization metho d o f that service. F or the set A of ba sic actions, w e tak e a gain the s et { f .m | f ∈ F , m ∈ M} . T A pt has the sor t T of BT A and in addition the sort TV of thr e ad ve ct ors . T o build terms of sor t T , T A pt has the constants a nd op e rators of BT A and in addition the follo wing additional constants and op e rators : – for each i ∈ N , the internal ly c ontr ol le d switch-over co nstant S i : T ; – the external ly c ontr ol le d switch-over constant E : T ; – the p oly-thr e adi ng o p erator  ⊥ : T × TV → T ; – for ea ch k ∈ N + , 4 the k -a ry external choi c e op erato r  k : T × · · · × T | {z } k times → T . T o build terms of sort TV , T A pt has the followin g constants and op erator s: – the empty thr e ad ve ctor co nstant h i : TV ; – the singleton thr e ad ve ctor op era tor h i : T → TV ; – the thr e ad ve ctor c onc atenation op er ator y : TV × TV → TV . Throughout the pap er, we assume that there are infinitely many v aria bles of sort TV , including α, β , γ . In the cont ext of the p oly-threa ding oper ator  ⊥ , the constants S i and E a re alternatives for the co nstant S which pro duce additional effects. Let p , p 1 , . . . , p n be closed terms of sort T . The n  ⊥ ( p, h p 1 i y . . . y h p n i ) fir st b ehaves as p , but when p terminates: – in the case where p terminates with S , it terminates; – in the case where p terminates with S i : • it co nt in ues b y b ehaving as  ⊥ ( p i , h p 1 i y . . . y h p n i ) if 1 ≤ i ≤ n , • it dea dlo cks otherwis e; – in the case wher e p terminates with E , it con tin ues by b ehaving as one of  ⊥ ( p 1 , h p 1 i y . . . y h p n i ), . . . ,  ⊥ ( p n , h p 1 i y . . . y h p n i ) or it deadlocks. Moreov er, the basic action tl s . init is p erformed betw een termination and contin u- ation. In the ca se where p ter minates with E , the choice b etw een the alter na tives is made externally . Nothing is stipulated ab out the effect that the constants S i and E pr o duce in the ca se where they o ccur outside the co nt ext of the p o ly- threading op erator . The p oly-threa ding o per ator concerns sequencing of thr eads. A threa d selec- tion involv ed in se quencing o f threa ds is called a n aut onomous thr e ad sele ction if the selection is made b y the terminating thre a d. Otherwise, it is called a non-autonomous thr e ad s ele ction . T he constants S i a re meant for autonomous 4 W e write N + for the set { n ∈ N | n > 0 } . Throughout th e p ap er, we u se th e conv ention that k and n stand for arbitrary elements of N + and N , resp ectively . 7 T able 4. Axioms for p oly- threading  ⊥ ( S , α ) = S SPT1  ⊥ ( D , α ) = D SPT2  ⊥ ( x E a D y , α ) =  ⊥ ( x, α ) E a D  ⊥ ( y , α ) SPT3  ⊥ ( S i, h x 1 i y . . . y h x n i ) = tls . init ◦  ⊥ ( x i , h x 1 i y . . . y h x n i ) if 1 ≤ i ≤ n SPT4  ⊥ ( S i, h x 1 i y . . . y h x n i ) = D if i = 0 ∨ i > n SPT5  ⊥ ( E , h x 1 i y . . . y h x k i ) =  k ( tls . init ◦  ⊥ ( x 1 , h x 1 i y . . . y h x k i ) , . . . , tls . init ◦  ⊥ ( x k , h x 1 i y . . . y h x k i )) SPT6  ⊥ ( E , h i ) = D SPT7 thread selections and the constant E is meant for no n-autonomous threa d selec - tions. W e remark that non-auto no mous thread selectio ns are immateria l to the joint b ehaviours of pro gram fragments r eferred to above. In the case of a non-a utonomous thread selection, it comes to an external choice betw ee n a n um ber of threa ds . The externa l choice op erato r  k concerns external choice betw een k threads. Le t p 1 , . . . , p k be closed ter ms of so r t T . Then  k ( p 1 , . . . , p k ) behaves as the outcome o f an e x ternal c hoice betw een p 1 , . . . , p k and D . T A pt has the axio ms o f BT A a nd in addition the axioms given in T able 4. In this table, a stands for a n arbitrary a ction from A tau . The additional axio ms express that threads are se q uenced by p oly-threading a s desc r ib ed ab ov e. There are no axio ms fo r the externa l choice op er a tors because their basic pro pe r ties cannot be expr essed as equations or conditional e q uations. F o r e a ch k ∈ N + , the basic prop erties o f  k are expres s ed b y the following disjunction of equa tions: W i ∈ [1 ,k ]  k ( x 1 , . . . , x k ) = x i ∨  k ( x 1 , . . . , x k ) = D . 5 T o b e fully precise , we should give axioms c o ncerning the constants and op erator s to build terms of the sor t TV a s w ell. W e refrain fro m doing so beca use the constan ts and o p e rators co nce rned a re the usual ones for seq uences. Similar remarks apply to the sort D T V intro duced later and will not b e rep ea ted. Guarded recur sion can b e added to T A pt as it is added to BT A in Section 2. W e will wr ite T A pt +REC for T A pt extended with the constants for solutions of guarded recursive sp ecifications and axio ms RDP and RSP. The use mechanism ca n b e added to T A pt as it is added to BT A in Section 3. Let T stand for either T A pt or T A pt +REC. Then we will write T +TSU for T extended with the use o p erator s and the axioms from T able 3. 5 In ternalization of Non-Autonomous Thread Selection In the ca se of non-autono mous thread selection, the selection of a thr ead is made ex ter nally . In this section, w e show how non-autono mous thr ead s election can b e internalized. F o r that purp ose, we first extend T A pt with po stconditional 5 W e use the notation [ n, m ], where n, m ∈ N , for the set { i ∈ N | n ≤ i ≤ m } . 8 T able 5. Axioms for p ostconditional switc hing tau D k ( x 1 , . . . , x k ) = t au D k ( x 1 , . . . , x 1 )  ⊥ ( a D k ( x 1 , . . . , x k ) , α ) = a D k (  ⊥ ( x 1 , α ) , . . . ,  ⊥ ( x k , α )) tau D k ( x 1 , . . . , x k ) / f H = tau D k ( x 1 / f H , . . . , x k / f H ) g .m D k ( x 1 , . . . , x k ) / f H = g .m D k ( x 1 / f H , . . . , x k / f H ) if ¬ f = g f .m D k ( x 1 , . . . , x k ) / f H = tau ◦ ( x i / f ∂ ∂ m H ) if H ( h m i ) = i ∧ i ∈ [1 , k ] f .m D k ( x 1 , . . . , x k ) / f H = D if ¬ H ( h m i ) ∈ [1 , k ] switching. P ostconditional switching is like postconditio na l comp ositio n, but c ov- ers the case where services pro cessing ba s ic actions produce reply v alues from the set N instea d of reply v alues from the set { T , F } . Postconditional s witching is conv enien t when internalizing non-autonomous thread selection, but it is not necessary . F or each a ∈ A tau and k ∈ N + , we introduce the k -a ry p ostc onditiona l switch op erator a D k : T × · · · × T | {z } k times → T . Let p 1 , . . . , p k be clo s ed terms of s ort T . Then a D k ( p 1 , . . . , p k ) will first p erform ac tion a , and then pro ceed a s p 1 if the pro cessing o f a leads to the re ply 1 , . . . , p k if the pro c e ssing of a leads to the reply k . The axioms for the p ostconditiona l switching op erato rs ar e given in T a ble 5. In this table, a stands for an ar bitrary actio n from A tau , f and g stand for arbitrar y fo ci from F , and m stands for an arbitrary metho d from M . W e pr o ceed with the internalization of non-autonomo us thread selections. Let p , p 1 , . . . , p k be closed terms of s o rt T . The idea is that  ⊥ ( p, h p 1 i y . . . y h p k i ) can be internalized b y: – replacing in  ⊥ ( p, h p 1 i y . . . y h p k i ) all occurr ences of E by S k +1; – app e nding a thread that ca n make the thr ead selec tio ns to the threa d vector. Sim ultaneous with the replacement of all occur rences of E b y S k +1, all o ccur - rences of S k +1 m ust be repla ced b y D to pr even t inadverten t selectio ns of the app ended thread. When making a thread selection, the app ended thre a d has to request the ex ter nal en v ironment to giv e the p osition of the thread that it would ha ve selected itself. W e make the simplifying ass umption that the ex ternal environmen t can b e viewed as a service. Let p , p 1 , . . . , p k be clo s ed ter ms of sor t T . Then the int ernalization of  ⊥ ( p, h p 1 i y . . . y h p k i ) is  ⊥ ( ρ ( p ) , h ρ ( p 1 ) i y . . . y h ρ ( p k ) i y h ext . sel D k ( S 1 , . . . , S k ) i ) , where ρ ( p ′ ) is p ′ with sim ulta neously all occurr ences of E replaced by S k +1 a nd all occ urrences of S k + 1 replaced by D . Here , it is assumed that ext ∈ F a nd sel ∈ M . Postconditional switching is not really neces sary for internalization. Let k 1 = ⌊ k / 2 ⌋ , k 2 = ⌊ k 1 / 2 ⌋ , k 3 = ⌊ ( k − k 1 ) / 2 ⌋ , . . . . Using postco nditional compo sition, 9 first a s e le ction can b e made b etw een { p 1 , . . . , p k 1 } and { p k 1 +1 , . . . , p k } , next a selectio n can be made b etw e en { p 1 , . . . , p k 2 } and { p k 2 +1 , . . . , p k 1 } or betw een { p k 1 +1 , . . . , p k 3 } a nd { p k 3 +1 , . . . , p k } , dep ending on the outcome of the previous selection, etcetera. In this w ay , the n um ber of actions p erformed to se lect a thread is betw een ⌊ 2 log( k ) ⌋ and ⌈ 2 log( k ) ⌉ . 6 A CP with Conditions In Section 7, we will inv estigate the connections of threads a nd ser vices with the pro cesses consider ed in A CP-style pro cess algebras. W e will fo cus on ACP c , an extension of ACP with conditions in tro duced in [5]. In this section, w e shor tly review A CP c . A CP c is a n extension of A CP with conditional expr essions in which the conditions a r e taken fro m a Bo olean algebr a. A CP c has tw o sorts: (i) the sort P of pr o c esses , (ii) the sor t C of c onditions . In ACP c , it is assumed that the following has b een giv en: a fixed but arbitrary set A (of actions), with δ 6∈ A , a fixed but arbitrar y set C at (of a to mic conditions), and a fixed but arbitra ry commutativ e and asso ciative function | : A ∪ { δ } × A ∪ { δ } → A ∪ { δ } such that δ | a = δ for all a ∈ A ∪ { δ } . The function | is rega rded to giv e the result of synchronously p erforming an y tw o actio ns for which this is p ossible, and to b e δ otherwise. Henceforth, w e wr ite A δ for A ∪ { δ } . Let p and q b e close d terms of sort P , ζ and ξ b e clos e d term of sort C , a ∈ A , H ⊆ A , and η ∈ C at . In tuitiv e ly , the constan ts and op erato rs to build terms of sort P that will be used to define the pro cesses to whic h threa ds and services corresp ond can be explained a s follows: – δ can neither perfor m an a ction nor terminate s uccessfully; – a first perfor ms action a unconditionally and then termina tes success fully; – p + q b ehaves either as p or as q , but not bo th; – p · q first b ehav es as p , but when p terminates s uccessfully it co ntin ues as q ; – ζ : → p behaves as p under condition ζ ; – p k q b ehaves as the proc ess that pro ceeds with p a nd q in par allel; – ∂ H ( p ) behaves the same as p , except that actions fro m H are block ed. Int uitiv ely , the co ns tants and op er ators to build terms of sort C that will b e used to define the pro c esses to whic h threads and services corr esp ond can be explained as follows: – η is an atomic co ndition; – ⊥ is a c ondition that nev er holds; – ⊤ is a c ondition that alw ays holds; – − ζ is the opp os ite of ζ ; – ζ ⊔ ξ is either ζ or ξ ; – ζ ⊓ ξ is bo th ζ and ξ . The remaining op erators of A CP c are of an auxiliary nature. They are needed to axiomatize A CP c . The axioms of ACP c are given in [5]. 10 W e write P i ∈I p i , where I = { i 1 , . . . , i n } and p i 1 , . . . , p i n are terms of sort P , for p i 1 + . . . + p i n . The conv en tion is that P i ∈I p i stands for δ if I = ∅ . W e use the notatio n p ⊳ ζ ⊲ q , where p and q ar e ter ms of sort P and ζ is a term o f sort C , for ζ : → p + − ζ : → q . A pro cess is considere d definable over A CP c if there exis ts a guarded recursive sp ecification ov er ACP c that has that pro cess as its so lution. A r e cursive sp e cific ation over A CP c is a set of r ecursion equatio ns E = { X = t X | X ∈ V } , where V is a set of v ar iables and each t X is a term of sort P that only contains v a riables fro m V . Let t b e a ter m of sor t P containing a v ar ia ble X . Then an o ccurrenc e of X in t is guar de d if t ha s a s ubterm of the fo rm a · t ′ where a ∈ A and t ′ is a term containing this o ccur rence o f X . Let E b e a recursive sp ecification ov er A CP c . Then E is a guar de d r e cursive sp e cific ation if, in each equation X = t X ∈ E , all occur rences of v a riables in t X are guar ded or t X can be rewritten to such a ter m using the ax io ms of ACP c in either direction and/or the equations in E except the equatio n X = t X from left to r ight. W e only consider mo dels o f ACP c in which guarded recursive sp ecifica tio ns hav e unique solutions, such a s the full splitting bisimulation mo de ls o f ACP c presented in [5]. F or each guar de d r ecursive s pec ification E and ea ch v ar iable X that o c c urs as the left-hand side of a n equation in E , we in tro duce a constant of s o rt P standing for the unique so lution o f E for X . This constan t is deno ted by h X | E i . The axioms for guarded recursion are als o given in [5]. In o r der to expres s the use op erator s, we need an extensio n of A C P c with action r enaming o per ators. Intuitiv ely , the action renaming op erato r ρ f , wher e f : A → A , ca n b e explained as fo llows: ρ f ( p ) b ehaves as p with each action replaced according to f . The axio ms for action r enaming are the ones given in [13] a nd in addition the equation ρ f ( φ : → x ) = φ : → ρ f ( x ). W e write ρ a ′ 7→ a ′′ for the r enaming o pe r ator ρ g with g defined by g ( a ′ ) = a ′′ and g ( a ) = a if a 6 = a ′ . In o rder to explain the connectio n of threads and services with ACP c fully , we need an extension o f ACP c with the co ndition ev aluation op era tors CE h int ro duced in [5]. In tuitiv ely , the condition ev alua tio n opera tor CE h , where h is a function on conditions that is preserved by ⊥ , ⊤ , − , ⊔ and ⊓ , can b e explained as follows: CE h ( p ) b ehav e s as p with each condition replaced acco rding to h . The impo rtant p oint is tha t, if h ( ζ ) ∈ {⊥ , ⊤} , all subter ms of the form ζ : → q ca n b e eliminated. The axioms for condition ev aluation are also giv en in [5]. 7 Threads, Services and ACP c -Definable Pro cesses In this section, we relate threads a nd ser vices a s cons idered in T A pt +REC+TSU to pro cesses that are definable o ver ACP c with action renaming. F or that purpose , A , | a nd C at are tak en a s follows: A = { s f ( d ) | f ∈ F , d ∈ M ∪ R} ∪ { r f ( d ) | f ∈ F , d ∈ M ∪ R} ∪ { s ext ( n ) | n ∈ N } ∪ { r ext ( n ) | n ∈ N } ∪ { stop , stop , stop ∗ , i } ∪ { s serv ( r ) | r ∈ R} ∪ { r serv ( m ) | m ∈ M} ; 11 for all a ∈ A , f ∈ F , d ∈ M ∪ R , m ∈ M , r ∈ R and n ∈ N : s f ( d ) | r f ( d ) = i , s f ( d ) | a = δ if a 6 = r f ( d ) , a | r f ( d ) = δ if a 6 = s f ( d ) , s ext ( n ) | r ext ( n ) = i , s ext ( n ) | a = δ if a 6 = r ext ( n ) , a | r ext ( n ) = δ if a 6 = s ext ( n ) , stop | stop = stop ∗ , stop | a = δ if a 6 = stop , a | stop = δ if a 6 = stop , i | a = δ , s serv ( r ) | a = δ , a | r serv ( m ) = δ ; and C at = { H ( h m i ) = r | H ∈ S , m ∈ M , r ∈ R} . F or each f ∈ F , the set A f ⊆ A and the function R f : A → A ar e defined as follows: A f = { s f ( d ) | d ∈ M ∪ R} ∪ { r f ( d ) | d ∈ M ∪ R} ; for all a ∈ A , m ∈ M and r ∈ R : R f (s serv ( r )) = s f ( r ) , R f (r serv ( m )) = r f ( m ) , R f ( a ) = a if V r ′ ∈R a 6 = s serv ( r ′ ) ∧ V m ′ ∈M a 6 = r serv ( m ′ ) . The s ets A f and the functions R f are us ed b elow to express the use op erator s in terms of the opera tors o f A CP c with action renaming. F or conv enience, w e intro duce a sp ecial no tation. Let α b e a term o f sort TV , let p 1 , . . . , p n be terms of sor t T such tha t α = h p 1 i y . . . y h p n i , and let i ∈ [1 , n ]. Then w e write α [ i ] for p i . W e pro ceed with rela ting threads and ser v ices as cons idered in T A pt +REC+ TSU to pro cess e s de fina ble over ACP c with action rena ming. The under lying idea is that threads and ser vices can be viewed as pro cess e s that are definable ov er A CP c with action r enaming. W e define those pro cesses by mea ns o f a transla tion function [ [ ] ] from the s e t of all terms of sort T to the set o f all function from the set of all terms o f so r t TV to the set of all terms of s o rt P and a translatio n function [ [ ] ] from the set of all services to the set of all terms of sort P . These translation functions are defined inductiv ely by the equations given in T able 6, where w e write in the last equa tion t H ′ for the term X m ∈M r serv ( m ) · s serv ( H ′ ( h m i )) · ( X ∂ ∂ m H ′ ⊳ H ′ ( h m i ) = T ⊔ H ′ ( h m i ) = F ⊲ X H ′ ) + stop . Let p be a closed term of sort T . Then the pr o c ess algebr aic interpr etation of p is [ [ p ] ]( h i ). Henceforth, we write [ [ p ] ] for [ [ p ] ]( h i ). Notice that ACP is sufficient for the translation of terms of sort T : no con- ditional expres sions o ccur in the transla tio ns. F or the tra nslation of s e r vices, we need the full pow er o f A CP c . 12 T able 6. Definition of translation funct ions [ [ X ] ] ( α ) = X [ [ S ] ]( α ) = stop [ [ D ] ]( α ) = i · δ [ [ t 1 E tau D t 2 ] ]( α ) = i · i · [ [ t 1 ] ]( α ) [ [ t 1 E f .m D t 2 ] ]( α ) = s f ( m ) · (r f ( T ) · [ [ t 1 ] ] ( α ) + r f ( F ) · [ [ t 2 ] ] ( α )) [ [ S i ] ]( α ) = tls . init · [ [ α [ i ]] ] ( α ) if 1 ≤ i ≤ len( α ) [ [ S i ] ]( α ) = i · δ if i = 0 ∨ i > len( α ) [ [ E ] ]( α ) = P i ∈ [1 , len( α )] r ext ( i ) · tls . init · [ [ α [ i ]] ] ( α ) + i · δ [ [  ⊥ ( t , α ′ )] ]( α ) = [ [ t ] ]( α ′ ) [ [  k ( t 1 , . . . , t k )] ]( α ) = P i ∈ [1 ,k ] r ext ( i ) · [ [ t i ] ]( α ) + i · δ [ [ h X | E i ] ] ( α ) = h X |{ X = [ [ t ] ]( α ) | X = t ∈ E }i [ [ t / f H ] ]( α ) = ρ stop ∗ 7→ stop ( ∂ { stop , stop } ( ∂ A f ([ [ t ] ]( α ) k ρ R f ([ [ H ] ])))) [ [ H ] ] = h X H |{ X H ′ = t H ′ | H ′ ∈ S }i The tra nslations given above preserve the axioms o f T A pt +REC+TSU. Roughly sp eaking, this means that the tra nslations o f these axioms are deriv a ble from the axio ms o f ACP c with action rena ming a nd guarded recur sion. Before w e make this fully pre cise, we hav e a clos er lo o k at the axioms of T A pt +REC+TSU. A prop er a xiom is an equation o r a conditional equation. In T ables 1 –4, we do not o nly find pro p er axioms. In a ddition to pr op er axioms , we find: (i) ax- iom schemas witho ut side conditions; (ii) axiom schemas with syn tactic s ide conditions; (iii) axio m schemas with se ma ntic side conditio ns . The a xioms of T A pt +REC+TSU are obtained by replacing eac h axiom sc hema b y all its in- stances. Owing to the presence of a x iom schemas with seman tic side conditions, the axio ms of T A pt +REC+TSU include prop er axioms and axioms with s eman- tic side conditions. Ther efore, semantic side co nditions take part in the tra ns- lation of the a xioms a s w ell. The instances of TSU5, TSU6, and TSU7 are the only axio ms of T A pt +REC+TSU with semantic side co nditions. These semantic side conditions, b eing o f the form H ( h m i ) = r , are loo ked upo n as elements o f C at . Consider the set that consists of: – all equations t 1 = t 2 , where t 1 and t 2 are terms of sort T ; – all conditional equations E ⇒ t 1 = t 2 , wher e t 1 and t 2 are ter ms of sort T and E is a set of equations t ′ 1 = t ′ 2 where t ′ 1 and t ′ 2 are terms of sort T ; – all expressions t 1 = t 2 if φ , where t 1 and t 2 are terms of sort T and φ ∈ C at . W e define a tr anslation function [ [ ] ] from this s e t to the set of a ll equations of A CP c with action renaming and guarded re c ursion as follows: [ [ t 1 = t 2 ] ] = [ [ t 1 ] ] = [ [ t 2 ] ] , [ [ E ⇒ t 1 = t 2 ] ] = { [ [ t ′ 1 ] ] = [ [ t ′ 2 ] ] | t ′ 1 = t ′ 2 ∈ E } ⇒ [ [ t 1 ] ] = [ [ t 2 ] ] , [ [ t 1 = t 2 if φ ] ] = CE h Φ ∪{ φ } ([ [ t 1 ] ]) = CE h Φ ∪{ φ } ([ [ t 2 ] ]) , 13 where Φ = { V r ∈R ¬ ( H ( h m i ) = r ∧ W r ′ ∈R\{ r } H ( h m i ) = r ′ ) | H ∈ S , m ∈ M} . Here h Ψ is a function on co nditions of A CP c that preserves ⊥ , ⊤ , − , ⊔ and ⊓ and satisfies h Ψ ( ζ ) = ⊤ iff ζ corresp onds to a pr op osition deriv able from Ψ and h Ψ ( ζ ) = ⊥ iff − ζ corresp onds to a propo sition deriv a ble from Ψ . 6 Theorem 1 (Preserv ation). L et ax b e an axiom of T A pt +REC+TSU . Then [ [ ax ] ] is derivable fr om the axioms of ACP c with action r enaming and guar de d r e cursion. Pr o of. The pro of is straig ht forward. In [6 ], we outline the pro o f for axio m TSU5. The other axioms are pro ved in a similar wa y . ⊓ ⊔ 8 Execution Arch itectures for F ragm en t ed P r ograms An analytic execution architecture in the sense o f [12 ] is a model of a hypo thetical execution en vironment for sequential progr ams that is designed for the purp ose o f explaining ho w a progr am may b e executed. An ana lytic execution ar chitecture makes explicit the interaction o f a progr am with the comp onents of its exec utio n environmen t. T he notio n o f a na lytic execution architecture defined in [12] is suited to sequential pro grams that hav e not b een split in to frag ments. In this section, we discuss analytic execution architectures suited to sequential pr o grams that hav e been split into fragments. The notion o f analytic execution architecture fro m [12] is defined in the s et- ting of pro gram algebra. In [4], a threa d e x traction op era tio n | | is defined which gives, for eac h pro g ram co nsidered in prog ram alg ebra, the thread that is taken for the b ehaviour exhibited by the progra m on e x ecution. In the ca se of progr ams that ha v e b een split into fra g ments, additional instructions for switc hing o v er execution to a nother pro gram frag ment ar e needed. W e assume that a collection of prog ram fragments b etw een which execution can b e switc hed tak es the form of a s equence, calle d a n pr ogram fra gment v ector, and that there is an additional instruction ### i for each i ∈ N . Switc hing ov e r execution to the i - th progr am fragment in the progr am frag ment vector is effected by exe cuting the instruction ### i . If i eq uals 0 or i is gr eater than the length of the prog ram fragment vector, exe cution of ### i results in dea dlo ck. W e ex tend thread extraction a s follows: | ### i | = S i , | ### i ; x | = S i . An a na lytic execution architecture for progra ms that have b een split into fragments c o nsists of a comp onent c ontaining a progr am fra gment, a c o mp o nent containing a prog ram fra gment vector and a num b er of servic e comp onents. The comp onent containing a progr am fr agment is capable of pro c essing instruc tio ns 6 Here we use “corres p onds to” fo r the wo rdy “is isomorphic to the equiv alence class with resp ect to logical equiv alence of ” (see also [5] ). 14 one at a time, iss uing appropriate requests to ser vice compo nents a nd aw aiting replies from ser v ice compone nts as describ ed in [12] in so far as instructions other than s witch-o v er instructions are concerned. This implies that, for e ach service comp onent, there is a channel for commun ication b etw een the prog ram fragment comp onent and that serv ice comp onent and that fo ci are used as names of tho s e channels. In the case of a sw itch-ov er instr uction, the comp o ne nt containing a progra m fragment is capable of loading the progra m fragment to whic h execution m ust be sw itched from the comp one nt containing a progr am fragment vector. The ana lytic execution ar chitecture made up of a comp onent c o ntaining the progra m fragment P , a comp onent containing the progr am fragment vector α = h P 1 i y . . . y h P n i , and service co mpo nents H 1 , . . . , H k with c hannels na med f 1 , . . . , f k , resp ectively , is descr ib ed by the thr e ad  ⊥ ( | P | , h| P 1 |i y . . . y h| P n |i ) / f 1 H 1 . . . / f k H k . In the case where instructions of the form ### i do not o ccur in P , [ [  ⊥ ( | P | , h| P 1 |i y . . . y h| P n |i ) / f 1 H 1 . . . / f k H k ] ] agrees with the pro c e s s-algebr aic descr iption given in [12] o f the analytic execu- tion architecture ma de up o f a comp onent co n taining the pro gram P and service comp onents H 1 , . . . , H k with c hannels named f 1 , . . . , f k , resp ectively . 9 P oly-Threaded St rategic In terlea ving In this section, we take up the extension of T A pt with a form of interleaving suited for m ulti-threading. Multi-threading refers to the concurr e nt existence of several threads in a progra m under ex ecution. Multi-threading is provided by contemporar y pro - gramming language s suc h as J av a [14] and C# [15 ]. Ar bitrary interleaving, on which ACP [1], CCS [17] and C SP [16] a re based, is not an appropr iate abstrac- tion when dealing with multi-threading. In the case o f multi-threading, s ome deterministic interlea ving strategy is used. In [8 ], we intro duce d a num b er of plausible deterministic interleaving strateg ies for m ulti-threading. W e pro po sed to use the phrase strategic int erleaving for the more c onstrained form of in- terleaving obtained by using s uch a strategy . In this sectio n, we consider the strategic in terleaving of fragmented pr ogra m b e haviours. As in [8], it is assumed that the collection of thr eads to be interlea ved takes the form of a thread vector. In this s ection, we o nly cov er the s implest interlea v- ing stra tegy for fragmented progr am behaviours, namely pure cyc lic interle av- ing . In the p oly-threa ded case , cyclic int erleaving basically opera tes as follows: at each stage of the interlea ving, the first thread in the threa d vector gets a turn to p erform a basic action or to switc h ov er to another thread and then the thread v ector undergo es cyclic pe r mutation. W e mea n b y cyclic per mut ation of a thread vector that the first threa d in the thread vector b eco mes the la st one and all other s mov e one position to the left. If one threa d in the thread vector 15 T able 7. Axioms for p oly- threaded cyclic in terlea vin g k  ⊥ ( h i , α ) = S PCI1 k  ⊥ ( h S i y β , α ) = k  ⊥ ( β , α ) PCI2 k  ⊥ ( h D i y β , α ) = S D ( k  ⊥ ( β , α )) PCI3 k  ⊥ ( h x E a D y i y β , α ) = k  ⊥ ( β y h x i , α ) E a D k  ⊥ ( β y h y i , α ) PCI4 k  ⊥ ( h S i i y β , h x 1 i y . . . y h x n i ) = tls . init ◦ k  ⊥ ( β y h x i i , h x 1 i y . . . y h x n i ) if 1 ≤ i ≤ n PCI5 k  ⊥ ( h S i i y β , h x 1 i y . . . y h x n i ) = S D ( k  ⊥ ( β , h x 1 i y . . . y h x n i )) if i = 0 ∨ i > n PCI6 k  ⊥ ( h E i y β , h x 1 i y . . . y h x k i ) =  k ( tls . init ◦ k  ⊥ ( β y h x 1 i , h x 1 i y . . . y h x k i ) , . . . , tls . init ◦ k  ⊥ ( β y h x k i , h x 1 i y . . . y h x k i )) PCI7 k  ⊥ ( h E i y β , h i ) = S D ( k  ⊥ ( β , h i )) PCI8 T able 8. Axioms for deadlock at termination S D ( S ) = D S2D1 S D ( D ) = D S2D2 S D ( x E a D y ) = S D ( x ) E a D S D ( y ) S2D3 S D ( S i ) = S i S2D4 S D ( E ) = E S2D5 S D (  k ( x 1 , . . . , x k )) =  k ( S D ( x 1 ) , . . . , S D ( x k )) S2D6 deadlo cks, the whole do es no t deadlo ck till all o thers hav e terminated or dea d- lo ck e d. An impo r tant pro pe r ty of cyclic in terleaving is that it is fair, i.e. there will alw ays come a next turn for all active threads. Other plausible interlea v- ing strategies are treated in [8]. They can a lso be a dapted to the poly-thr eaded case. The e x tension of T A pt with cyclic interleaving is ca lled T A pt si . It has the sorts T and TV of T A pt . T o build terms of sort T , T A pt si has the consta nt s and oper ators of T A pt to build terms of sort T a nd in addition the fo llowing op erator : – the p oly-thr e ade d cyclic str ate gic interle aving op erator k  ⊥ : TV × TV → T . T o build terms o f sort TV , T A pt si has the constan ts and op e r ators of T A pt to build terms of sort TV . T A pt si has the axioms of T A pt and in addition the axioms given in T ables 7 and 8. In these tables, a stands for an arbitrary action from A tau . The axioms from T able 7 e x press that threads ar e int erleav ed as des crib ed ab ov e. In these axioms, the aux iliary de ad lo ck at termination op era to r S D o ccurs. The a xioms from T able 8 show that this op er ator serves to turn termination into deadlo ck. Guarded recursio n and the use mechanism ca n b e added to T A pt si as they are added to BT A in Sections 2 a nd 3, respe c tively . 16 10 P oly-Threaded D ist ributed Strategic Interlea ving In this section, we take up the extension of T A pt with a form of interleaving suited for distributed m ulti-threading. In order to deal with threads that ar e distributed over the no des of a netw ork, it is assumed that there is a fixed but arbitrary finite set L of lo c ations s uch that L ⊆ N . The set L A of lo c ate d b asic actions is defined by L A = { l.a | l ∈ L ∧ a ∈ A} . Henceforth, ba s ic a c tions will also b e called unlo c ate d b asic actions . The mem ber s of L A ∪ { l . tau | l ∈ L} ar e r eferred to as lo c ate d actions . Performing a n unlo c ated a c tion a is taken as performing a at a lo cation still to b e fixed b y the distributed interleaving stra tegy . Performing a loc ated action l .a is tak en as p erforming a at lo cation l . Threads that per form unlo cated actio ns only a r e ca lle d u nlo c ate d threads and thr eads that per fo rm lo cated actio ns only ar e called lo c ate d threads. It is assumed that the collection o f all threads that ex ist co ncurrently at the s a me lo cation ta kes the form of a sequence of unlo cated threads, called the lo c al thr e ad ve ctor at the lo cation co nc e r ned. It is a lso a ssumed that the collection of lo ca l thread vectors that exist c o ncurrently at the different lo ca tio ns takes the form of a sequence of pairs, one for each locatio n, consisting of a lo ca tion and the lo cal thread vector a t tha t lo ca tion. Such a seq uence is called a distribute d thr e ad ve ctor . In the distributed case, cyclic in terleaving ba s ically op era tes the s ame as in the non-distributed ca se. In the distributed case, we mean by cyclic p ermutation of a distributed threa d vector that the first thread in the first lo cal thread vector bec omes the last thread in the first lo cal thread vector, all other threads in the first loca l threa d vector mo v e one pos ition to the left, the resulting lo cal thread vector beco mes the last lo cal threa d vector in the distributed thread vector, and all other lo cal thread vectors in the dis tributed threa d vector mov e one position to the left. When discussing interleaving strategies o n distributed thread vectors, we use the term current thread to r efer to the first thread in the first lo ca l threa d vector in a dis tr ibuted thre a d v ector and we use the ter m c ur rent lo cation to refer to the locatio n at which the first local thread vector in a distributed thread v ector is. The extension of T A pt with cyclic distributed interlea ving is called T A pt dsi . It has the sorts T and TV of T A pt and in addition the follo wing so rts: – the sort L T of lo c ate d thr e ads ; – the sort D T V of distribute d t hr e ad ve ctors . T o build ter ms o f sort T , T A pt dsi has the co nstants and o p er ators of BT A and in addition the follo wing oper ators: – for each n ∈ N , the migr ation p ostc onditional c omp osition op erator E mg ( n ) D : T × T → T . T o build terms of sort TV , T A pt dsi has the constants and op erator s o f T A pt to build terms of so rt TV . T o build terms of sort L T , T A pt dsi has the following constants and op erato rs: 17 – the de ad lo ck constant D : L T ; – the termination constant S : L T ; – for each l ∈ L and a ∈ A tau , the p ostc onditional c omp osition op erator E l .a D : L T × L T → L T ; – the de ad lo ck at termination ope r ator S D : L T → L T ; – the p oly-thr e ade d cyclic distribute d str at e gic int erle aving op era tor k  ⊥ : D T V × TV → L T . T o build terms of sort D T V , T A pt dsi has the followin g constants a nd op erator s : – the empty distribute d thr e ad ve ctor cons tant h i : D T V ; – for eac h l ∈ L , the singleton distribute d thr e ad ve ctor oper ator [ ] l : TV → D T V ; – the distribute d thr e ad ve ct or c onc atenation oper ator y : D T V × D T V → D T V . Throughout the pap er , we assume that there ar e infinitely many v ariables o f so rt L T , including u, v , w , and infinitely many v a riables of sort D T V , including δ . W e in troduce lo c ate d action pr efixing a s an abbreviation: l .a ◦ p , where p is a term of s ort L T , a bbreviates p E l .a D p . The ov e rloading of D , S , h i and y could b e res olved, but we r efrain from doing so becaus e it is alw ays clear from the context w hich constant or op erator is meant. Essentially , the so rt D T V includes all sequences of pairs consisting of a lo- cation and a lo ca l thread vector. 7 The ones that co ntain a unique pair for each lo cation are the prop er distributed thr ead v e c tors in the sense tha t the cyclic distributed interleaving strategy outlined a bove is intended for them. Improp er distributed thread vectors that do not contain duplicate pairs fo r so me lo ca- tion a r e needed in the axiomatiza tion of this strateg y . Improp er distributed thread v ectors that do contain duplicate pairs for some lo cation a pp e ar to have more than o ne lo ca l thread vector at the lo catio n concerned. Their exclusion would make it nece ssary for conca tenation of distributed thread vectors to be turned into a partial o pe r ator. The cyclic distr ibuted interleaving str ategy never turns a proper distributed thread vector into an improp er one or the o ther way round. The p o ly-threaded cyclic distributed s trategic interlea ving op erator ser ves for interleaving o f the threads in a prop er distributed thread vector a ccording to the s trategy outlined ab ove, but with supp ort of e x plicit threa d migr ation. In the case where a loca l threa d v ector of the for m h p E mg ( n ) D q i y γ with n ∈ L is encountered a s the first lo cal thread vector, γ b ecomes the la st lo cal thread vector in the distributed thread vector a nd p is app ended to the loc a l thr ead vector at lo cation n . If n 6∈ L , then γ y h q i b e comes the last local thread vector in the distributed thread v ector. In the axioms for cyclic distr ibuted interleaving dis cussed b elow, binary func- tions app l (where l ∈ L ) from unlocated threa ds a nd distributed thread v ectors 7 The singleton distribut ed thread vector op erators invo lve an implicit pairing of th eir operand with a location. 18 T able 9. Definition of the functions app l app l ( x, h i ) = h i app l ( x, [ γ ] l ′ y δ ) = [ γ y h x i ] l y δ if l = l ′ app l ( x, [ γ ] l ′ y δ ) = [ γ ] l ′ y app l ( x, δ ) if l 6 = l ′ T able 10. Axioms for p ostconditional composition u E l. tau D v = u E l. tau D u L T1 T able 11. Axioms for p oly-threaded cyclic d istributed interlea ving k  ⊥ ( h i , α ) = S PCDI1 k  ⊥ ([ h i ] l 1 y . . . y [ h i ] l k , α ) = S PCDI2 k  ⊥ ([ h i ] l y δ, α ) = k  ⊥ ( δ y [ h i ] l , α ) PCDI3 k  ⊥ ([ h S i y γ ] l y δ, α ) = k  ⊥ ( δ y [ γ ] l , α ) PCDI4 k  ⊥ ([ h D i y γ ] l y δ, α ) = S D ( k  ⊥ ( δ y [ γ ] l , α )) PCDI5 k  ⊥ ([ h x E a D y i y γ ] l y δ, α ) = k  ⊥ ( δ y [ γ y h x i ] l , α ) E l .a D k  ⊥ ( δ y [ γ y h y i ] l , α ) PCDI6 k  ⊥ ([ h S i i y γ ] l y δ, h x 1 i y . . . y h x n i ) = l. tls . init ◦ k  ⊥ ( δ y [ γ y h x i i ] l , h x 1 i y . . . y h x n i ) if 1 ≤ i ≤ n PCDI7 k  ⊥ ([ h S i i y γ ] l y δ, h x 1 i y . . . y h x n i ) = S D ( k  ⊥ ( δ y [ γ ] l , h x 1 i y . . . y h x n i )) if i = 0 ∨ i > n PCDI8 k  ⊥ ([ h E i y γ ] l y δ, h x 1 i y . . . y h x k i ) =  k ( l. tls . init ◦ k  ⊥ ( δ y [ γ y h x 1 i ] l , h x 1 i y . . . y h x k i ) , . . . , l. tls . init ◦ k  ⊥ ( δ y [ γ y h x k i ] l , h x 1 i y . . . y h x k i )) PCDI9 k  ⊥ ([ h E i y γ ] l y δ, h i ) = S D ( k  ⊥ ( δ y [ γ ] l , h i )) PCDI10 k  ⊥ ([ h x E mg ( n ) D y i y γ ] l y δ, α ) = l. tau ◦ k  ⊥ ( app n ( x, δ y [ γ ] l ) , α ) if n ∈ L PCDI11 k  ⊥ ([ h x E mg ( n ) D y i y γ ] l y δ, α ) = l. tau ◦ k  ⊥ ( δ y [ γ y h y i ] l , α ) if n 6∈ L PCDI12 to distributed threa d vectors are used. F or ea ch l ∈ L , app l maps each unlo ca ted thread x and distributed threa d v ector δ to the distributed thread v ector ob- tained by app ending x to the lo cal thread vector at lo ca tio n l in δ . The functions app l are defined in T able 9. T A pt dsi has the axio ms o f T A pt and in addition the axioms given in T ables 10, 11 and 12 . In these tables, a stands for a n arbitrary action from A tau . The axioms from T a ble 11 express that threa ds a re in terleav ed as descr ib ed ab ove. The axioms from T ables 1 0 and 1 2 ar e the axioms fro m T a bles 1 and 8 adapted to lo cated threads. Guarded recursio n a nd the use mechanism ca n b e a dded to T A pt dsi as they a re added to BT A in Sections 2 a nd 3, respe c tively . 19 T able 12. Axioms for deadlo ck at termination S D ( S ) = D LS 2D1 S D ( D ) = D LS 2D2 S D ( u E a D v ) = S D ( u ) E a D S D ( v ) LS2D3 S D ( S i ) = S i LS 2D4 S D ( E ) = E LS 2D5 S D (  k ( u 1 , . . . , u k )) =  k ( S D ( u 1 ) , . . . , S D ( u k )) LS2D6 11 F r agmen t Searc hing b y Implicit Migration In Section 1 0, it was a s sumed that the same prog r am fragment b ehaviours a re av aila ble at ea ch lo catio n. In the case where this ass umption do e s not hold, distributed interleaving s trategies with implicit migratio n of threads to a chiev e av aila bility of fragments needed b y the thre ads are plaus ible. W e sa y that such distributed interleaving strategies ta ke care of fr a gment searching. In this section, we intro duce a v ar iation of the distributed interleaving s tr ategy from Section 10 with fragment sear ching. This res ults in a theory called T A pt dsi , fs . It is assumed that there is a fixed but a rbitrary set I of fr agment indic es such that I = [1 , n ] for some n ∈ N . In the case of the distributed in terleaving stra tegy with fragment sear ching, immediately after the current threa d has p erformed an action, implicit migr ation of that thread to another loca tion may tak e place. Whether migr a tion really takes place, dep ends on the fragments presen t at the current loca tion. The cur rent thread is implicitly migrated if the following condition is fulfilled: o n its next turn, the cur rent thr e a d ought to switch o v er to a fragment that is not present at the curre nt lo cation. If this conditions is fulfilled, then the current thread will be migra ted to the first among the lo c ations wher e the fragment concerned is present. T o deal with that, we have to enrich distr ibuted thread vectors. The new dis- tributed thread vectors are sequences of triples, one for e a ch lo cation, consisting of a lo ca tion, the lo cal thread vector at that loca tio n, and the s e t of all indices of fragments that are present at that lo cation. T A pt dsi , fs has the sa me so rts as T A pt dsi . T o build terms of the sorts T , TV a nd L T , T A pt dsi , fs has the s ame co ns tants and oper ators as T A pt dsi . T o build ter ms of sort D T V , T A pt dsi , fs has the followin g co nstants and op erator s: – the empty distribute d thr e ad ve ctor cons tant h i : D T V ; – for eac h l ∈ L and I ⊆ I , the singleton distribute d thr e ad ve ctor op era tor [ ] I l : TV → D T V ; – the distribute d thr e ad ve ct or c onc atenation oper ator y : D T V × D T V → D T V . That is, the opera tor [ ] l is replaced by the op erato r s [ ] I l . 20 T able 13. Definition of the fun ctions app ′ l app ′ l ( x, h i ) = h i app ′ l ( x, [ γ ] I l ′ y δ ) = [ γ y h x i ] I l y δ if l = l ′ app ′ l ( x, [ γ ] I l ′ y δ ) = [ γ ] I l ′ y app ′ l ( x, δ ) if l 6 = l ′ Essentially , the sort TV includes all sequences of unlo ca ted threads. These sequences may ser ve as lo cal thread vectors and as fr agment vectors. The se- quences that c ontain a thre a d for each fragment index a re pro pe r fr a gment vec- tors. In the case of fragment v ectors that con tain more threads, there appear to b e inacces s ible fragments and in the c ase of fragment v ectors that cont ain less threads , there app ear to be disabled fragments. Ina ccessible fra gments hav e no influence on the effectiv eness of cy clic distr ibuted interleaving with fragmen t searching. How ev er, disabled fragments may lead to implicit migra tio n to a lo- cation where a switch-ov er on the ne x t turn is no t po ssible as well. Should this case arise, the next turn will yield deadlo ck. In the ax ioms for cyclic distributed interleaving with fr agment searching dis - cussed below, bina r y functions app ′ l (where l ∈ L ) from unlo cated threads and distributed thread vectors to distr ibuted thread vectors are used which a re sim- ilar to the functions app l used in the axio ms for cyc lic distributed interlea ving without fragment searching given in Section 10. The functions app ′ l are defined in T able 13. Moreov er, a unary function pv on distributed thread vectors is used which per mutes distr ibuted thread vectors cy clicly with implicit migr ation as outlined ab ov e. The function pv is defined using tw o a uxiliary functions: – a function iml ′ mapping each fragment index i , distributed thread vector δ and loca tion l to the first loca tion in δ at which the frag men t with index i is present if the fra gment concer ned is pr esent anywhere, and locatio n l otherwise; – a function iml mapping each non-empty distributed thread vector δ to the first lo ca tion in δ at which the fra gment is present to which the curre n t thread ought to switch o v er o n its next turn if the current thread is in that circumstance and the fragment concerned is prese nt so mewhere, a nd the current lo ca tion otherwise. The function pv , as well as the auxiliary functions iml ′ and iml , are defined in T able 14. T A pt dsi , fs has the axioms of T A pt and in addition the a xioms given in T ables 10, 15 and 12. Guarded recurs ion and the use mechanism can be added to T A pt dsi , fs as they are added to BT A in Sec tio ns 2 and 3, re sp ectively . 21 T able 14. Definition of the funct ions iml ′ , iml and pv iml ′ ( i, h i , l ′ ) = l ′ iml ′ ( i, [ γ ] I l y δ, l ′ ) = l if i ∈ I iml ′ ( i, [ γ ] I l y δ, l ′ ) = i ml ′ ( i, δ, l ′ ) if i 6∈ I iml ([ h i ] I l y δ ) = l iml ([ h S i y γ ] I l y δ ) = l iml ([ h D i y γ ] I l y δ ) = l iml ([ h x E a D y i y γ ] I l y δ ) = l iml ([ h S i i y γ ] I l y δ ) = l if i ∈ I iml ([ h S i i y γ ] I l y δ ) = iml ′ ( i, δ, l ) if i 6∈ I iml ([ h E i y γ ] I l y δ ) = l iml ([ h x E mg ( n ′ ) D y i y γ ] I l y δ ) = l pv ( h i ) = h i pv ([ h i ] I l y δ ) = [ h i ] I l y δ iml ([ h x i y γ ] I l y δ ) = l ′ ⇒ pv ([ h x i y γ ] I l y δ ) = app ′ l ′ ( x, δ y [ γ ] I l ) T able 15. Axioms for cyclic distributed interlea ving with fragmen t searching k  ⊥ ( h i , α ) = S PCDIfs1 k  ⊥ ([ h i ] I l 1 y . . . y [ h i ] I l k , α ) = S PCDIfs2 k  ⊥ ([ h i ] I l y δ, α ) = k  ⊥ ( δ y [ h i ] I l , α ) PCDIfs3 k  ⊥ ([ h S i y γ ] I l y δ, α ) = k  ⊥ ( δ y [ γ ] I l , α ) PCDIfs4 k  ⊥ ([ h D i y γ ] I l y δ, α ) = S D ( k  ⊥ ( δ y [ γ ] I l , α )) PCDIfs5 k  ⊥ ([ h x E a D y i y γ ] I l y δ, α ) = k  ⊥ ( pv ([ h x i y γ ] I l y δ ) , α ) E l.a D k  ⊥ ( pv ([ h y i y γ ] I l y δ ) , α ) PCDIfs6 k  ⊥ ([ h S i i y γ ] I l y δ, h x 1 i y . . . y h x n i ) = l. tls . init ◦ k  ⊥ ( pv ([ h x i i y γ ] I l y δ ) , h x 1 i y . . . y h x n i ) if i ∈ I ∩ [1 , n ] PCDIfs7 k  ⊥ ([ h S i i y γ ] I l y δ, h x 1 i y . . . y h x n i ) = S D ( k  ⊥ ( δ y [ γ ] I l , h x 1 i y . . . y h x n i )) if i 6∈ I ∩ [1 , n ] PCDIfs8 k  ⊥ ([ h E i y γ ] I l y δ, h x 1 i y . . . y h x k i ) =  k ( l. tls . init ◦ k  ⊥ ( pv ([ h x 1 i y γ ] I l y δ ) , h x 1 i y . . . y h x k i ) , . . . , l. tls . init ◦ k  ⊥ ( pv ([ h x k i y γ ] I l y δ ) , h x 1 i y . . . y h x k i )) PCDIfs9 k  ⊥ ([ h E i y γ ] I l y δ, h i ) = S D ( k  ⊥ ( δ y [ γ ] I l , h i )) PCDIfs10 k  ⊥ ([ h x E mg ( n ) D y i y γ ] I l y δ, α ) = l . tau ◦ k  ⊥ ( app ′ n ( x, δ y [ γ ] I l ) , α ) if n ∈ L PCDIfs11 k  ⊥ ([ h x E mg ( n ) D y i y γ ] I l y δ, α ) = l . tau ◦ k  ⊥ ( pv ([ h y i y γ ] I l y δ ) , α ) if n 6∈ L PCDIfs12 22 12 Conclusions W e have developed a theory of the b ehaviours exhibited b y sequen tial pro grams on execution that covers the case where the prog rams hav e b een split in to frag - men ts and hav e used it to descr ib e analytic e x ecution arc hitectures suited for such programs. It happens that the resulting desc r iption is terse. W e hav e a lso shown that threads a nd services as considere d in this theory can b e viewed as pro cesses that are defina ble ov er a n extensio n of A CP with conditions . Threads and ser vices are introduced for pra gmatic rea sons only: describing them as gen- eral pro ce sses is awkw ard. F or exa mple, the description of ana lytic execution architectures suited for programs that ha v e bee n split in to fragments w ould no longer be ters e if ACP with conditions had b een used. W e hav e also taken up the e x tension of the theory develope d to the ca se where the steps of fragmented pr o gram behaviours are in terleav ed in the wa ys of non-distributed a nd distr ibuted multi-threading. This work can b e further elab orated on the lines of [9] to cov er issues such as pr even tion fro m migra tion for threa ds that keep lo cks on shared services, loa d balancing b y means of implicit migration, and the use of implicit migration to a chiev e av aila bility of services needed by threads. The o b ject pursued with the line of research that w e have car ried on with this pap er is the developmen t of a theor etical under s tanding of the concepts sequential pro gram a nd seq uential progr am b ehaviour. W e regard the work pre- sented in this pap er a lso as a preparato r y step in the development of a theore tica l understanding of the concept oper ating system. References 1. Baeten, J.C.M. , W eijland, W.P .: Process Algebra, Cambridge T r acts in The or etic al Computer Scienc e , vol. 18. Cambridge U niversit y Press , Cambridge (1990) 2. Bergstra, J.A., Bethk e, I.: Polarize d pro cess alg ebra and program equ iv alence. In : J.C.M. Baeten, J.K. Lenstra, J. P arro w, G.J. W o eginger (eds.) Pro ceedings 30th ICALP , L e ctur e Notes in Computer Scienc e , vol. 2719, p p. 1–21. Sprin ger-V erlag (2003) 3. Bergstra, J.A., Bethke, I., Ponse, A.: Decision problems for pushd o wn threads. Acta Informatica 44 (2), 75–90 (2007) 4. Bergstra, J.A., Lo ots, M.E.: Program algebra for sequential code. Journal of Logic and Algebraic Progra mming 51 (2), 125–156 (2002 ) 5. Bergstra, J.A., Middelburg, C.A.: Splitting b isim ulations and retrosp ective condi- tions. Information and Computation 204 (7), 1083–113 8 (2006) 6. Bergstra, J.A., Middelburg, C.A.: Thread algebra with multi-leve l strategies. F un- damenta Informaticae 71 (2/3), 153–182 (2006) 7. Bergstra, J.A., Middelburg, C.A.: Instruction sequences with indirect jumps. Sci- entific Ann als of Computer Science 17 , 19–46 (2007) 8. Bergstra, J.A., Middelburg, C.A.: Thread algebra for strategic in terlea ving. F ormal Asp ects of Comput ing 19 (4), 445–474 (2007) 9. Bergstra, J.A., Middelburg, C.A.: Distributed strategic interlea ving with load bal- ancing. F uture Generation Computer Systems 24 (6), 530–54 8 (2008) 23 10. Bergstra, J.A., Middelburg, C. A.: Thread algebra for sequential p oly- threading. Electronic Rep ort PRG0804, Programming Researc h Group, Universit y of Am- sterdam (2008). Av aila ble at http://www.s cience.uv a.nl/research/prog/ publicatio ns.html , also av ailable at http://arxiv .org/ : ArXiv:0803 .0378v1 [cs.LO] 11. Bergstra, J.A., Middelburg, C.A.: Thread extraction for p olyadic instruction se- quences. Electronic Rep ort PRG0803 , Programming R esearc h Group, Un iversi ty of Amsterdam (2008). Ava ilable at http://www .science. uva.nl/res earch/prog/ publicatio ns.html , also av ailable at http://arxiv .org/ : ArXiv:0802 .1578v1 [cs.PL] 12. Bergstra, J.A., Ponse, A .: Execution architectures for program algebra. Journal of Applied Logic 5 , 170–192 (2007) 13. F okkink , W.J.: Introduction to Pro cess Algebra. T ex t s in Theoretical Computer Science, An EA TCS Series. S pringer-V erlag, Berlin (2000) 14. Gosling, J., Jo y , B., Steele, G., Bracha, G.: The Ja v a Language Sp ecification, second edn. Addison-W esley , Reading, MA (2000) 15. Hejlsberg, A., Wiltamuth, S., Golde, P .: C# Language Sp ecification. Addison- W esley , Reading, MA (2003) 16. Hoare, C.A.R.: Communicating Sequential Pro cesses. Prentice-Hall, Englewood Cliffs (1985) 17. Milner, R.: Communicatio n and Concurren cy . Prentice-Hall, Englewood Cliffs (1989) 18. P onse, A., v an der Zw aag, M.B.: An in troduction t o program and thread algebra. In: A . Beckmann, et al. (eds.) CiE 2006, L e ctur e Notes in Computer Scienc e , vol. 3988, pp. 445–458. Springer-V erlag (2006) 19. Sannella, D., T arlec ki, A.: Algebraic p reliminaries. In : E. A stesiano, H.J. Kreowski, B. Krieg-Br ¨ uckner (eds.) Algebraic F oundations of Systems Sp ecification, p p. 13– 30. Springer-V erlag, Berlin (1999 ) 20. Wirsing, M.: Algebraic sp ecification. I n: J. v an Leeuw en (ed.) Handbo ok of Theo- retical Computer S cience, vol. B, p p. 675–788. Elsevier, Amsterdam (1990) 24

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment