CSC3150 Assignment 2
Homework Requirements
Environment
WARNING!!! Before starting on this assignment, make sure you have set up your VM properly. We would test all students’ homework using the following environment. You can type the following command in terminal on your VM to see if your configuration matches the test environment. If not, you are still good to go, but please try to test your program with the following environment for at least once. Because you may be able to run your program on your environment, but not on TAs’ environment, causng inconvenience or even grade deduction.
If you follow the tutorials then your VM setting should be fine, though verify your environment again is recommended.
Linux Version
The versions of Ubuntu from 16.04 to 22.04 are ok. You can use the following command to get it.
Linux Kernel Version
4.4 or 5.10.x is ok (Test Environment). You can use the following command to get it.
GCC Version
4.9 above. Use “gcc –version” to get it.
cat /etc/issue
Ubuntu 20.04
5.10 (or 4.4)
Code Help, Add WeChat: cstutorcs
Submission
Due on: 23:59, 25 Oct 2023
Please note that, teaching assistants may ask you to explain the meaning of your program, to ensure that the codes are indeed written by yourself. Please also note that we would check whether your program is too similar to your fellow students¡¯ code using plagiarism detectors.
Late submission: A late submission within 15 minutes will not induce any penalty on your grades. But 00:16 am-1:00 am: Reduced by 10%; 1:01 am-2:00 am: Reduced by 20%; 2:01 am-3:00 am: Reduced by 30% and so on. (e.g. Li Hua submit a perfect attemp of hw1 on 2:10 am. He will get (100+10 (bonus))*0.7=77 points for his hw1.
Here is the format guide. The project structure is illustrated as below. You can also use ls command to check if your structure is fine. Structure mismatch would cause grade deduction.
Please mark whether you have finished bonus in your report.
gcc –version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Report.pdf 3150-p2-bonus-main/ source/
Two directories and one pdf, the “source/” directory is for the game ¡°Frog
crosses river¡± and “3150-p2-bonus-main/” directory is for the bonus task.
Please compress all files in the file structure root folder into a single zip file and name it using your student id as the code showing below and above, for example, Assignment_2_120010001.zip. The report should be submitted in the format of pdf, together with your source code. Format mismatch would cause grade deduction. Here is the sample step for compress your code.
浙大学霸代写 加微信 cstutorcs
zip -q -r Assignment_2_120010001.zip Assignment_2_120010001
Assignment_2_120010001 Assignment_2_120010001.zip
Task Description
In the “source/” directory of Assignment 2, you are required to complete the multithread program to implement the game ¡°Frog crosses river¡±.
Game rules:
A river has logs floating on it, and a frog must cross the river by jumping on the logs as they pass by.
Log: ================= Frog: 0
River bank: |||||||||||||||||||||
When the game starts, the frog stands in the middle of bottom bank of river. The user can control the frog jumps by keyboards. The logs will move from left to right or right to left staggerly. Please take care of the edge cases.
Q: Quit the game
You will win if the frog jumps to the other bank of river successfully.
You will lose if the frog lands in the river, or the log reaches the left/right side of the river but the frog still on it.
Please note that this is a game. If the player suffers from extereme difficulty, high latency, and other unexpected situations for a game, your grade will suffer as well.
Function Requirements (90 points):
To run the template, you will see the frog stands in the middle at bottom bank of river. There are 9 blank rows which means the river. Compile the program to see the static output. (5 points)
You should complete the function named ¡°logs_move¡± to let the logs can move staggerly from left to right or from right to left. (20 points)
You should create pthread and use mutex lock for logs and frog movement control. (30 points)
¡°kbhit¡± function is provided for keyboard capture. You should complete the jump rules for keyboard actions. And the frog¡¯s position should be updated when keyboard hits. (15 points)
When the logs are moving, the program should be able to judge the game status (win, lost or quit). Print out the message for user whether he/she wins or lost the game. (15 points)
If the user quits the game, print the message. (5 points)
Demo Output
Demo output for user wins the game
Demo output for user loses the game:
Demo output for user quits the game:
You win the game!!
You lose the game!!
You exit the game.
Bonus Task (10 pionts)
void async_init(int num_threads)
void async_run(void (*handler)(int), int args)
async_run(void (*handler)(int), int args)
void async_init(int num_threads)
while(1){sleep(any);}
DL_APPEND(my_queue->head,
DL_DELETE(my_queue->head, my_queue->head);
async_init
Attention: The bonus task has no relationship with the the above game ¡°Frog crosses river¡±. Moreover, the task is a little bit difficult and will spend a lot of time to do. So never mind if you could not finish it.
In the “3150-p2-bonus-main/” directory of this bonus task, you have to implement correctly two important functions of a thread pool. The two functions in async.c are as follows:
(3 points)
(7 points).
Implement in async.c and async.h:
You can use list data structure in utlist.h, for example: (adding to queue end) and
(popping from queue head)
When no jobs are coming, your threads created in
not allowed to do busy waiting like
sleeping thread in your thread pool must wake up immediately (that is, no call is allowed).
async_run should be asynchronous without further call to pthread_create, that is it should return immediately before the job is handled (in the code we give you, async_run runs
have to go to sleep and is , and when jobs are coming a
synchronously, so you need to rewrite the function)
After finishing these two function and the implementation of thread pool, you can make with the provided Makefile and a http server will be run based on the thread pool you implement so that you can see whether your implementation works or not.
Please see the directory 3150-p2-bonus-main and read README.md in detail to do this bonus task.
What is a thread pool? Please see: https://en.wikipedia.org/wiki/Thread_pool. Report (10 points)
Write a report for your assignment, which should include main information as below:
Your name and student id.
How did you design your program?
The environment of running your program. (E.g., version of OS and kernel) The steps to execute your program.
Screenshot of your program output.
What did you learn from the tasks?
Grading rules
Here is a sample grading scheme. Different from the points specified above, this is the general guide when TA’s grading.
Completion Marks
Bonus 10 points
Report 10 points
Completed with good quality 80 ~ 90
Completed accurately 80 +
Fully Submitted (compile successfully) 60 +
Partial submitted 0 ~ 60
No submission 0