首页 > > 详细

Operating Systems Programming assignment 3. Multithread.

 Bachelor’s Degree in Computer

Science and Engineering
Operating Systems (2019-2020)
Programming assignment 3 -
Multithread
Computer Architecture and Technology Area
Universidad Carlos III de Madrid
Operating Systems
Programming assignment 3. Multithread. 
Bachelor’s Degree in Computer Science and Engineering
Bachelor’s Degree in Computer
Science and Engineering
Operating Systems (2019-2020)
Programming assignment 3 -
Multithread
Index
1. Practice statement....................................................................................................................2
2. Description of the programming assignment..........................................................................3
2.1 Cost calculation Manager in computer center...................................................................4
2.2 N-Producers & 1-Consumer..............................................................................................5
2.2.1 Queue on a circular buffer..........................................................................................6
2.3 Auto-correction..................................................................................................................7
3. Submission..............................................................................................................................8
3.1 Deadline.............................................................................................................................8
3.2 Submission........................................................................................................................8
3.3 Files to be submitted..........................................................................................................8
4. Rules......................................................................................................................................10
5. Appendix...............................................................................................................................11
5.1 man function....................................................................................................................11
6. Bibliography..........................................................................................................................12
1
Bachelor’s Degree in Computer
Science and Engineering
Operating Systems (2019-2020)
Programming assignment 3 -
Multithread
1. Practice statement
This programming assignment allows the student to become familiar with services used
for process management provided by POSIX.
For the management of lightweight processes (threads), the functions pthread_create,
pthread_join, pthread_exit, will be used and, mutex and conditional variable will be used
for the synchronization between them. 
 pthread_create: creates a new thread that executes a function that is indicated as
an argument in the call.
 pthread_join: waits for a thread that must end and that is indicated as an argument
in the call.
 pthread_exit: ends the execution of the process that makes the call.
The student must design and implement in C and for LINUX operating systems, a
program that acts as a manufacturing process manager. It will include several processes that
will be in charge of managing different phases of the factory and a process that will be in
charge of planning the different phases. 
2
Bachelor’s Degree in Computer
Science and Engineering
Operating Systems (2019-2020)
Programming assignment 3 -
Multithread
2. Description of the programming assignment
The objective of this programming assignment is to code a concurrent multi-threaded
system that calculates the cost of using the machines in a processing center. Given a file with
a specific format, you must calculate how much to charge the customer according to the type
of machines he wants to use, as well as the time he wants to use them. 
To realize the functionality, it is recommended to implement two basic functions, which
represent the roles of the program:
 Producer: It will be the function executed by the threads in charge of adding elements
in the shared circular queue.
 Consumer: It will be the function executed by the thread in charge of extracting
elements from the shared circular queue.
In this way, the program will have the following behavior:
Illustration 1. Example of operation with N producers, 1 consumer and a buffer.
I. The main thread will be the one in charge of:
a) Read the input arguments.
b) Load the data from the file provided into memory.
c) Distribute the file load among the number of producers threads indicated.
d) Launch the N producers and the consumer.
e) Wait for the finalization of all the threads and show the total calculated cost (result 
of waiting for the finalization of the consumer thread).
3
Bachelor’s Degree in Computer
Science and Engineering
Operating Systems (2019-2020)
Programming assignment 3 -
Multithread
II. Each producer thread must:
a) Obtain the data extracted from the file and insert them, one by one, in the circular 
buffer.
b) This task must be executed concurrently with the other producers, as well as the 
consumer. Under no circumstances may the threads be left "manually" blocked or 
an order forced between them (e.g. waiting for a thread to insert all its elements, or
those that fit in the queue, and then giving way to the consumer to remove them; 
then giving way to the next producer, etc.).
III. The consumer thread must:
a) Obtain concurrently, the elements inserted in the queue.
b) Each extracted element represents a type of machine and the time of use. 
Therefore, the consumer must calculate the cost and accumulate it until all the 
elements have been processed.
c) Once all the elements have been processed, the thread will finish its execution by 
returning the total calculated cost to the main thread. 
2.1 Cost calculation Manager in computer center
The main program will import arguments and data from the indicated file. To do this, it
must be considered that the execution of the program will be as follows:
./calculator
The label corresponds to the name of the file to be imported. The label
is an integer that represents the number of producer threads that you want
to generate. Finally, the label is an integer that indicates the size of the circular
queue (maximum number of elements that can be stored).
Additionally, the input file must have the following format:
4
500
1 1 4
2 2 12
3 1 100
4 3 45
...
Bachelor’s Degree in Computer
Science and Engineering
Operating Systems (2019-2020)
Programming assignment 3 -
Multithread
The first line of the file represents the number of operations to be calculated. There can be
more operations in the file, but only those indicated by this value should be processed. Under
any circumstances there may be fewer operations in the file than operations indicated by the
first value. 
The rest of the lines in the file represent an operation:
联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!