I've started implementing multitasking in my OS and the basis work well. I can have several user processes printing to the console via a system call and being rescheduled every X ms.
I'm now having a hard time figuring out what is a good way to implement a blocking system call. For instance, a keyboard driver. At the beginning I though of implementing it simply with a semaphore:
Code: Select all
keyboard_handler:
put char in buffer
V(sem)
get_char_blocking:
P(sem)
get char from buffer
Another thing I have thought of doing is something like that:
Code: Select all
keyboard_handler:
if waiter in list: give him the char by modifying its context and set him READY so that it will be rescheduled as soon as possible
else: put char in buffer
get_char_blocking:
if char: gets it and return
else: put me in waiting list
It seems to me that the first solution is cleaner: use of a well known synchronization primitive and interrupt handler kept simpler. But I don't see how it is possible to implement it like that ?
So here is my question: Is the second solution a good solution ? And if not, what is the proper way to make a blocking system call ?
Thank you
P.S. I hope that for once my question is not too stupid