Skip to content

auyu0408/ThreadScheduling

Repository files navigation

OS_HW3 ThreadScheduling

Directories

  • function_library.h, function_library.c -> Thread function
  • os_2021_thread_api.h, os_2021_thread_api.c -> Thread application interface function
  • self_thread.h, self_thread.c -> Self define data structure and related function
  • simulator.c -> main source
  • init_threads.json -> Thread configuration file
  • parsed_json.h, parsed_json.c -> Function to parsed init_threads.json file and CreateThread

Building the Project

  • install json-c library
sudo apt-get install libjson-c-dev
  • Git Hook install
make
  • compile simulator
make simulator
  • delete all output file
make clean

Usage

  • execute simulator
./simulator
  • Use Ctrl+Z to reports thread information
  • Use Ctrl+C to terminate the process
f1 wants to waiting for event 3
The priority of thread f1 is changed from M to H
f3 wants to waiting for event 3
The priority of thread f3 is changed from M to H
^Z
**************************************************************************************************
*	TID	Name		State		B_Priority	C_Priority	Q_Time	W_time	 *
*	0	reclaimer 	RUNNING		L		L		1200	0	 *
*	3	random_1  	READY		L		L		1480	0	 *
*	4	random_2  	READY		L		L		1480	0	 *
*	1	f1        	WAITING		M		H		0	2080	 *
*	2	f3        	WAITING		M		H		0	2080	 *
**************************************************************************************************
I found 65409.
random_1 changes the status of f1 to READY.
f1 wants to cancel thread random_1
f1 wants to cancel thread random_2
The priority of thread f1 is changed from H to M
^Z
**************************************************************************************************
*	TID	Name		State		B_Priority	C_Priority	Q_Time	W_time	 *
*	1	f1        	RUNNING		M		M		300	6600	 *
*	4	random_2  	READY		L		L		5080	0	 *
*	0	reclaimer 	READY		L		L		4780	0	 *
*	3	random_1  	READY		L		L		4780	0	 *
*	2	f3        	WAITING		M		H		0	7180	 *
**************************************************************************************************
The priority of thread f1 is changed from M to L
The memory space by random_2 has been released.
The memory space by random_1 has been released.
^Z
**************************************************************************************************
*	TID	Name		State		B_Priority	C_Priority	Q_Time	W_time	 *
*	0	reclaimer 	RUNNING		L		L		5400	0	 *
*	1	f1        	READY		M		L		1120	6600	 *
*	2	f3        	WAITING		M		H		0	8620	 *
**************************************************************************************************
^C

Test

There has 2 types case to test the os2021_thread_api.c, which is function_library0.c + init_thread0.json and function_library1.c + init_thread1.json
You could replace the original file with them.
You could also design your own function library and init_thread, don;t forget to include all_include.h
And the test case is modified from OS2021_Hw3_Template by TsenEn-Chou

Implementations

Structure In My Thread

  • thread name
  • thread id
  • original priority
  • current priority
  • cancel mode
    • 0: asynchronous
    • 1: deffer
  • cancel status
    • if thread's cancel mode is 1, when cancel status = 1, thread should cancel at cancel point
    • other's cancel status = 0
  • wait
    • -1: not waiting any event
    • 0~7: waiting some event
  • wait time
    • 0: no need to wait
    • >0: if thread need to wait for a while
  • already wait
    • if thread need to wait for a while, this will record how long you have wait
  • queueing time
  • waiting time
  • thread context
  • next thread
    • pointer pointed to next thread

Multilevel Feedback Queue

  • The two thing we considerate in our queue is: 1.Thread's priority 2. Enter order

    • If their priority is different, high priority serve first
    • Else, first come first serve
  • If the input order is: 1.L 2.H 3.M 4.M 5.H 6.L, the thread in queue be like:
    Head -> 2 -> 5 -> 3 -> 4 -> 1 -> 6

References

Releases

No releases published

Packages

No packages published