Name: Lica Robert-Mihai Class: 331
I implemented a shared library with a simulated thread scheduler for a single core processor.
Makefile
- linux makefile for building thelibscheduler.so
libraryscheduler.h
- header file for the scheduler implementationso_scheduler.h
- header file for the library's interface (to be used by the user)so_scheduler.c
- implementation of the schedulersch_thread.h
- header file for the information about threads hold by the schedulersch_thread.c
- implementation of the header filepq.h
- header file for the generic priority queuepq.c
- implementation of a generic priority queuedebug.h
- header with helpfull debug macrosutils.h
- header with error handling macros
The generic priority queue must receive as parameters function pointers to implementations of the copying and comparing of the provided data type. The time complexity is O(log N) for inserting and pop-ing the top and for peek-ing the top is O(1). The space complexity is O(n).
To sinchronize between threads and for one to signal another that he can start his work, I use semaphores as sincronization devices because unlocking mutexes from other threads than the one that locked it first results in undefined behaviour or error. (I had to change the implementation when observed this detail)
The planner is quite efficient as it keeps track of what thread was running before hand and makes the context switch only if needed, thus not needing to insert an element in the priority queue and another one to be taken out all the time.
- GitHub: Profile
- Geeksforgeeks page about the priority queue and inspiration for the code