581332
 Rinnakkaisohjelmistot (2 ov) 
 
 Kurssikoe 13.5.2004 
 
	- Vastaa lyhyesti
	seuraaviin kysymyksiin (9 p)
	- 
	Mitä tarkoitetaan
	lukkiutumisella (dead lock)  ja nälkiintymisellä
	(starvation)?  Anna aterioiviin filosofeihin perustuvat esimerkit 
	lukkiutumisesta ja nälkiintymisestä. (4 p)
	
 - 
	Miksi tuottajan ja
	kuluttajan väliin kannattaa laittaa puskuri? Miten puskurin
	koko vaikuttaa järjestelmän suorituskykyyn? (2 p)
	
 - 
	Miksi semaforien käyttö
	synkronoinnissa ja tahdistuksessa on suositeltavampaa kuin
	lukkomuuttujien käyttö? Mitä lisähyötyä
	on monitorista ?(3 p)
 
	
 -  Kaivuri ja kuorma-autot
	monitorissa (12 p) 
Pienellä
hiekkakuopalla on töissä yksi  kaivuri ja  useita
kuorma-autoja. Kaivuri on hiekka- kuopan pohjalla ja mättää
hiekkaa autoihin.Yksi kuorma-auto kerrallaan ajaa kuopan pohjalle,
odottaa kunnes  kuorma on täynnä ja sitten  poistuu
kuopalta. Kaivuri  taas odottaa kunnes hiekkakuopan pohjalla on
kuorma-auto ja täyttää auton lavan hiekalla. Anna
monitoria käyttävä ratkaisu kaivurin ja kuorma-autojen
toiminnan synkronointiin. Esitä myös  monitoria käyttävien
kaivuri- ja kuorma-autoprosessien  koodit.  
 
 
	 - 
	Museokäynti
	semaforeilla tahdistettuna (15 p) 
Museoon
järjestetään vain opastettuja kiertokäyntejä.
 Museoon halukkaat odottavat sisä-pihalla, kunnes opas saapuu ja
aloittaa uuden kierroksen. Kuitenkin, jos ryhmän koko on
pienempi kuin 10, niin opas jää odottamaan lisää
vierailijoita. Museokierroksen jälkeen vierailijat poistuvat
museosta muihin puuhiinsa ja opas varautuu opastamaan seuraavaa
ryhmää. 
Oletetaan,
että museossa kävijät ja opas  ovat  prosesseja ja 
niiden synkronointiin käytetään semaforeja. Kirjoita
prosessien toimintoja synkronoivat tarpeelliset koodit
opasprosessille ja  vierailijaprosesseilla.  
 
 
 
	 -  Tuottajat ja kuluttajat irallaan
	(15 p) 
Eri tietokoneisssa
asynkronisesti toimivat tuottaja- ja kuluttajaprosessit  hyödyntävät
erillisen puskuripalvelimen tarjoamaa  puskurointipalvelua.
Puskuripalvelin tarjoaa  rajallisen määrän
puskuritilaa, johon tuottajat vievät tuotoksensa ja josta
kuluttajat niitä hakevat. 
 
	-  Tuottaja- ja kuluttajaprosessit 
	kommunikoivat puskuripalvelimen kanssa etäproseduurikutsua
	(RPC) käyttäen. Kirjoita tarvittavat koodit ja määrittelyt
	prosessien toiminnan synkronointiin.(10 p) 
	 -  Oletetaan, että
	puskuripalvelimen  ja   tuottaja- ja  kuluttajaprosessien välinen
	yhteistoiminta toteutetaankin sanomanvälityksen avulla. Olisiko
	toiminnan synkronointi  nyt jollakin tavalla helpompaa vai 
	hankalampaa?  Jos, niin millä tavalla?  Miten  synkronointi 
	pääpiirteissään nyt tulisi toteuttaa?(5 p) 
 
 
 Kokeen palautustilaisuus on
keskiviikkona 26.5. klo 12-14  salissa C453. Kokeen tulokset ovat
ilmoitustaululla ja verkossa  viimeistään maanantaina 24.5.
 
 
581332
Concurrent Systems (2 cu) 
 
 
 Course
examination  13.5.2004 
	-  Answer shortly the following
	questions. (9 p) 
	-  What is meant by dead lock and
	starvation?  Give examples of  dead lock and   starvation, based on
	the problem of  the eating philosophers. (4 p)
	 
	 -   What is the use to put a buffer 
	between  a producer and a consumer? How does the size of the buffer
	affect the performance of the system? (2 p) 
	
	 -  Why is it better to use 
	semaphores for synchronization instead of locks? What advantages,
	compared to semaphores, do monitors bring?  (3p) 
	
 
	  
	 -   A digger and lorries in a monitor
	(12 p) 
A digger and
several lorries are working in a small sand-pit. Obviously, the
digger is not allowed to start to fill the lorry, if there is now
lorry in the pit. New lorries are not allowed to drive down to the
pit, if there is already a lorry in the pit. The lorry is not allowed
to leave the pit before it is fully loaded. Write the code  needed
for the co-operation of the digger and lorries  using a monitor for
synchronization.  Write also the code  for the   digger
process    and  lorry processes  that  use the monitor. 
 
 
 	 - 
	A visit to a museum   syncronized    by semaphores (15 p)
 The
museum offers only guided tours to the visitors. The arriving 
visitors wait in the entrance hall until the guide comes and starts 
a new tour. If the group size is less than 10  the guide has to wait
for further visitors. After the tour the visitors leave the museum 
to do other things and the guide is ready to start a new tour.
 
The  guide and the visitors are processes  that are   syncronized    using semaphores.  Write the routines, necessary  for the    synchronization    of their activities, for both  the visitor processes and the   guide    process. 
	
 -   Producers and consumers apart (15 p)
Consumer  and  
producer  processes run in different computers  and  to be able to
work asynchronically  they use services
provided by separate a buffer server. The buffer server provides a
limited amount of buffer space, where  producers  store their outputs
 before  consumers  fetch them. 
 
	-   The producer and consumer
	processes  communicate with the  buffer server  by using remote
	procedure calls (RPC). Write the necessary codes and declarations
	for the synchronization of the processes.
	(10 p) 
	 -  Suppose the  buffer server  and  
	producer and consumer processes  communicate by using message
	passing.  Would it now be easier or more difficult to synchronize
	the operation and in which way would it be easier or more difficult?
	 How should the synchronization now in principle  be done? (5 p) 
	  
 
 
 The results of the examination will
be in the intranet and  on notice board  at latest on Monday the 24th
of May.  On Wednesday the  26th of May   12-14  in room
C453 you can come to look at 
your own answer papers  and  assure yourself   that the grade given
to you is in line with your answers.    
 
 
 
 
 Muistin virkistämiseksi
                                                        To fresh up
your memory 
process foo  [i = 1 to n] {
 int sum = 0;
 int c [1:n] = ([n] 0);  # comment
 for [i = 1 to 10]  sum = sum + 1;
  }
 monitor M { 
   declarations; 
   procedure A ( formals) {
      body of A; 
   } 
   procedure B( formals) { 
      body of B; 
   } 
 } 
 
 
 module S 
     op op1 (int par1, type par2; result type out); 
     op op2( ); 
 body 
      declarations; 
      proc op1(par1, par2, out) { 
          statements; 
      } 
     proc op2( ) {
          statements; 
      } 
     
     process Internal { 
         statements; 
    } 
 
 end S 
 
 module C
      op op1 (formals1), op2 (formals2);
 body 
     process P1 { 
          declarations; 
          while (true) { 
              in   op1 (formals1) and B1  by e1 -> S1; 
             [ ]   op2( formals2) and B2  by e2 -> S2; 
              ni 
            } 
     } 
 end C