Return to Operationg Systems home
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
A binary files contains triplets of numbers
c x n
that individuate the monomial
x are real values (
n is an integer value (
Fon instance, the triplet
1.0 2.0 3
indicates the monomial
1.0*2.0^3, which is equal to the value
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.
fscanf/fprintf primitives to read/write (on the binary file).
lseek system call to perform the read of only the data related to the correct monomial.