6CCS3RSC/7CCSMRTS
Assignment 3: Scheduling
19th February 2019
For this assignment, you will need the code for program multithread.c. Download this from the module¡¯s KEATS page before continuing with the below.
Examine the code for program multithread.c and make sure that you understand what it does.
1. Run the code and record the output in your report. To run this program you need to use sudo (i.e., use the command: sudo ./multithread). Briefly explain (using one or two paragraphs) what this program does and how the scheduling gives rise to the observed behaviour. Include in your re- port a timing diagram; be sure to show the state of each task (including the main routine) at all times.
Modify the threadA function so that after printing half the letters it increases the priority of threadB using the instructions:
param.sched priority = priority min+2;
pthread setschedparam(threadB id,policy,¶m);
Make sure that you understand what these changes do.
2. Run the modified program (using sudo) and record the output. Draw a timing diagram showing the state of each task (including the main routine) at all times. Explain the scheduling of the threads. Modify the code to decrease the priority of threadB after threadA has printed half its letters. Report what happens and comment on this result. Modify the priority of only the executing thread and report what happens when the priority is increased and when it is decreased. Comment on and explain these results.
[25 marks]
3. Modify the original program so that threadA sleeps for 1 millisecond after printing half its letters (use the nanosleep command). Run the code (using sudo) and record the output. Draw a timing diagram and explain the scheduling of the threads. Include a print-out of your program code.
[25 marks]
4. Change the scheduling policy used by multithread.c to be SCHED RR rather than SCHED FIF0. Perform experiments to determine how these scheduling policies differ. Describe the experiments
Dr M. Howard Dept. Informatics, King¡¯s College London
[25 marks]
that you performed and summarise the results. Describe in your report how both scheduling policies determine the scheduling of tasks both when threads have equal priority and when when threads have unequal priorities. Include a print-out of your program code.
[25 marks]
Completed assignments should be submitted to KEATS on 8th March 2019, 23.55.
Your report must be no longer than four A4-pages (including all diagrams and mathematical derivations).
It should be submitted as a single PDF with a minimum font size of 11pt. This assignment is worth 10% of the module mark.
Dr M. Howard 2 Dept. Informatics, King¡¯s College London