Table of Contents

Return to Operationg Systems home


Operating Systems Course: Lab09

Laboratory number 09

Exercise 01: concurrent programs with semaphores

A file contains a text in the ASCII format with indefinite length, but its lines have a maximum length of 100 characters.

Write a multi-threads concurrent program that:

All three threads are cyclic and they must be created only one time. When the first thread identifies the end of the file, it must allow the second and third thread an ordered termination, and it terminates itself.
To synchronize threads use the semaphoric primitives sem_*.

Exercise 02: concurrent programs with semaphores

A binary files contains triplets of numbers
c x n
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
1.0 2.0 3 indicates the monomial 1.0*2.0^3, which is equal to the value 8.0.

Triplets have to be considered in groups of 3. Each triplet belongs to the same monimial.

Write a multi-thread program that:

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).

Assume that does not exist mathematical operation beyond the 4 main ones. In other words, all the threads compute the monomials:

c * x^n

using the multiplication

c * x * x * x * x ... n times.

The 4 threads terminate in an ordered way, when the end of the file is reached.
The main thread waits for the 4 executed threads, and then it ends itself.

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.

Suggestions: