User Tools

Site Tools


os:lab10
Return to Home page

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
os:lab10 [2019/12/19 07:25]
zioskenz
os:lab10 [2019/12/29 23:29] (current)
zioskenz
Line 20: Line 20:
  
  
-==== Exercise 02 ====+==== Exercise 02: concurrent programs with semaphores ​====
 A binary files contains triplets of numbers\\ A binary files contains triplets of numbers\\
 ''​c x n''​\\ ''​c x n''​\\
-that individuates ​the monomial ''​c*x^n'',​ where ''​c''​ and ''​x''​ are real values (''​float''​) and ''​n'' ​in an integer value (''​int''​). ​+that individuate ​the monomial ''​c*x^n'',​ where ''​c''​ and ''​x''​ are real values (''​float''​) and ''​n'' ​is an integer value (''​int''​). ​
  
 Fon instance, the triplet\\ Fon instance, the triplet\\
Line 32: Line 32:
 Each triplet belongs to the same monimial. Each triplet belongs to the same monimial.
  
-Si scriva un programma concorrente ​multi-thread in grado di:+Write a multi-thread ​program that: 
 +  * receives from the command line a string. This string specifies the name of an input file containing the previous specified records, but in binary format. 
 +  * executes 4 cyclic threads: 
 +    * the first thread computes the first monomial of each polynomial. 
 +    * the second thread computes the second monomial of each polynomial. 
 +    * the third thread computes the third monomial of each polynomial. 
 +    * the fourth thread computes the sum of the 3 monomials, and prints (in the screen) the value of the polynomial.
  
-- ricevere sulla riga di comando una stringa. +All the threads are **cyclic**, and read from the file only the information (monomials) of their competence (i.e., you must avoid that the first 3 threads read the whole input file).
-  Tale stringa specifica il nome di un file di ingresso +
-  contenente ​record precedentemente specificati in formato +
-  binario.+
  
-- esegue 4 thread ciclici: +Assume that does **not** exist mathematical operation beyond the main ones
-  - il primo thread calcola il primo monomio di ciascun polinomio. +In other words, all the threads compute the monomials:​ 
-  - il secondo thread calcola il secondo monomio di ciascun polinomio. +<code txt>
-  - il terzo thread calcola il terzo monomio di ciascun polinomio. +
-  - il quarto thread effettua la somma dei 3 monomi e visualizza +
-    (a video) il valore del polinomio. +
- +
-Tutti i thread sono ciclici e leggono da file solo le informazioni +
-(monomi) di loro competenza (si eviti quindi che i primi 3 thread +
-leggano tutti l'​intero file di ingresso). +
- +
-Si supponga ​*nonesistano operazioni matematiche oltre le principali+
-In altre parole tutti i thread calcolino i monomi+
 c * x^n c * x^n
-tramite moltiplicazione +</​code>​ 
-c * x * x * x * x ... n volte+using the multiplication 
- +<code txt> 
-I 4 thread terminino ordinatamente una volta raggiunta la fine del +c * x * x * x * x ... n times
-file. +</​code>​
-Il thread principale attenda i 4 eseguiti e termini esso stesso.+
  
-Il file di ingresso si puo' supporre di formato correttoma +The 4 threads terminate in an ordered waywhen the end of the file is reached.\\ 
-se il numero di monomi memorizzati su file non e' multiplo di 3 +The main thread waits for the 4 executed threads, and then it ends itself.
-il valore dei monomi mancanti sia uguale a 0.+
  
-Suggerimenti:​ +The input file can be assumed correct, but if the number of monomials stored in the file it is not multiple of 3, the value of the missing monomials is equal to 0.
-- Si scriva un programma/​funzione di conversione tra il formato ASCII e il +
-  formato binario e se necessario (per verifica) un programma/​funzione +
-  che effettui la conversione opposta. +
-- La conversione venga effettuata mediante serializzazione. +
-- Si utilizzino le primitive di lettura scrittura fscanf/​fprintf (sul file +
-  di testo) e read/write (sul file binario). +
-- Ciascun thread utilizzi lseek per effettuare la lettura dei soli +
-  dati del monomio corretto.+
  
 +**Suggestions:​**
 +  * Write a program/​function to convert between the ASCII format and the binary format, and if it is necessary (for verification) a program/​function that performs the conversion in the opposite direction.
 +  * The conversion is done with serialization.
 +  * Use the ''​fscanf/​fprintf''​ primitives to read/write (on the binary file).
 +  * Each thread can make use of the ''​lseek''​ system call to perform the read of only the data related to the correct monomial.

If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/os/lab10?rev=1577658577&do=diff
/web/htdocs/www.skenz.it/home/data/pages/os/lab10.txt · Last modified: 2019/12/29 23:29 by zioskenz

Privacy Policy