Assignment 5, due Sept 27
Part of
the homework for 22C:116, fall 2002
|
http://homepage.cs.uiowa.edu/~dwjones/opsys/threads/
The usual way for a C program to read a character from standard input is to call ch=getchar(); for many purposes, this is equivalent to the Unix kernel call read(0,&ch,1). (Under Unix, file descriptor zero is standard input.)
The Problem: Write, thread_getchar(), a routine to read a character from standard input under the thread manager. This would have to allow other threads to run until a character was available on standard input.
Suggestion: You could use the select() Unix kernel call to implement this, or you could you use the O_NONBLOCK option for the open() kernel call (opening /dev/tty, the current interactive terminal) to implement this, or you could use fcntl to set the O_NONBLOCK attribute of file descriptor zero, which is already open. (See the unix man pages for documentation of these services!)
A Problem: Under certain circumstances, some of the kernel calls suggested above allow thread-getchar() to make fewer than 1 kernel call per character being read. What implementation would allow this, and under what circumstances will this be true?
A Hint: Consider the difference between getchar() as defined in <stdio.h> and the Unix kernel call read(0,&ch,1). You can read the source for the former in /usr/include/stdio.h.
Further, suppose our disk I/O driver uses the elevator algorithm for disk I/O scheduling, and that it uses the trick suggested in the course notes to use the pending requests in the disk queue as a cache.
A Question: Explain the relationship between the process manager, the disk interrupt service routine and the page-fault handler. Focus on the time when the disk I/O transfer required to service a page fault is completed.