C代写|多线程代写|OS代写-CS 361 Project Assignment 6

C代写|多线程代写|OS代写: 这是一个涉及多线程的题目,主要利用多线程处理相关的问题,加深对多线程的理解

CS 361 – Project Assignment 6

For this project, you need to implement a multi-threaded version of the supervisor processfrom PA5. Thus, the required functionality for the Project is the same as for Project 5:

Your program needs to take a single command line argument (which is the name of a datafile containing JPG and HTML fragments) and create two files:

1. "classification", which has the classification file format, and contains the classification
data for each cluster of the input file.
2. "map", which has the map file format, and contains the mapping data for each cluster
of the input file to the correct cluster of a data file.

Again, your program will need to create multiple child processes, and use message queuesto communicate with the parent process. For details on the tasks and message formats,please refer to the Project5 page.

Worker Processes (children)

For this PA, you are given a binary that runs on student.cs.jmu.edu, which implements theworker functionality. When creating the worker processes, the supervisor process will callexeclp() to run the binary in each worker process. The provided skeleton code already doesthis, so you do not need to change anything. If you are using your own Linux system, thereis a chance that the worker binary does not run, in this case, I suggest you develop onstudent.cs.jmu.edu, or use your Project 5 child process code initially, before you migrate yourcode to student.cs.jmu.edu.

Supervisor process (parent)

The functionality of the supervisor process also remains the same. However, for thisproject, you need to create multiple threads to work on different parts of the functionality.There will now be a main thread as well as NUM_THREADS number of processor threads.The main thread is responsible to create tasks and add them to the tasks queue, and theprocessor threads are responsible to receive and process messages from the results queue.The processor threads are only doing work in Phase 1.

The supervisor process first needs to generate names for the message queues, and thenfork NUM_PROCESS number of children. It then proceeds to enter three distinct phases:

Phase 1: generate classification tasks and process results

In this phase, the main thread first needs to create NUM_THREADS processor threads,whose functionality is described further below. The main task then goes on to generate a

classification task for each cluster of the input file and to add them to the tasks queue.Because the processor threads will be responsible to receive messages from the resultsqueue, the main thread can send messages to the tasks queue in blocking mode. When themain thread has sent all the classification tasks, it needs to wait for the processor threadsto finish, and then enter Phase 2.

The processor tasks concurrently will try to receive messages from the results queue (inblocking mode). When a result has been received for a thread, it needs to perform thefollowing steps:

seek to the correct location in the classification file as specified by res_cluster_number
write the classification type to the location
if the classification type indicates a file header, the cluster number is also saved in a
data structure for use in Phase 2. It is recommended that you use the provided intqueue
queue data structure for this purpose, but you are free to implement you own storage

Once classification results for all clusters have been processed, the processor threads needto terminate.

Phase 2: generate map tasks

In this phase, the supervisor process needs to generate a map task for every "headercluster" remembered in Phase 1. Assuming you are using a queue to store these clusters,the following pseudo code describes the activities for this phase:

while the queue is not empty:get next cluster number from queue^if the cluster is a JPG header:^generate a new JPG file name^else:^generate a new HTML file name^generate the task message for the cluster, and send it to the tasks queue^

Once all map tasks have been sent, Phase 3 starts (i.e. the results queue is not being usedanymore).

Phase 3: generate termination tasks

In this phase, the supervisor process needs to generate a terminate task for every childprocess it created, and send it to the tasks queue. The supervisor process then closes anyopen file or message queue descriptors, unlinks the message queues, and terminates itself.


Your tasks message queue must be named "/tasks_<your stu login>", where <your
stu login> is your user name on stu.cs.jmu.edu. The provided skeleton code provides
for that, so do not change it.
Your results message queue must be named "/results_<your stu login>", where <your
stu login> is your user name on stu.cs.jmu.edu. The provided skeleton code provides
for that, so do not change it.
Both the tasks and the results queue should be configured to have 1000 maximum
messages, and a maximum message size of MESSAGE_SIZE_MAX (defined in common.h)
You may use a buffer of size MESSAGE_SIZE_MAX when receiving messages. I.e. you^
can declare this as a local variable instead of dynamically allocating it.
Whenever you use a shared variable or data structures among different threads, be
sure to protect access and modification operations with a mutex.

Source code files

You are given skeleton code for this project, which contains the following files:

common.h - a header file containing constants to be used by all code
classify.h - a header file containing function signatures for the classification functions
classify.c - a source file containing code that implements the classification functions
intqueue.h - a header file containing function signatures for the operations on a
queue data structure that stores types int as its element data.
intqueue.c -a source file containing code that implements the^ integer queue functions
project6.c - a skeleton source file for the main application^
Makefile - a make file for the project
worker - a binary compiled and linked on stu.cs.jmu.edu, that the supervisor's child
processes need to execute

For this project, only modify the project6.c file. You may not create any additional files. Youmay not change the Makefile. Your code must work with the Makefile provided. If you wantto implement your own data structure for storing the "header clusters", then you must doso entirely in project6.c (including any struct definitions).


In your PDF report, include a detailed description of how your program works (1-2 pages).Name your PDF document "-project6.pdf". Place place it and your final"project6.c" file inside a directory "-project6", and zip (or tar/gzip) the entiredirectory to a file called "-project6.zip" (or .tgz). When I unzip the file, thedirectory must be created! Submit the archive file for your submission in Canvas.


电子邮件地址不会被公开。 必填项已用*标注