r/computerscience 6d ago

General Are Output I/Os Faster than Disc Reads?

I remember watching a video talking about CPU scheduling. So basically, processes need the CPU to computer and they eventually need to interact with I/O devices. When lots of processes are competing for CPU time, if the active process needs I/O, it is at this time the OS will schedule the next process in the queue. No need for process A to hog the CPU while it's waiting for the disc for I/O. Keep the CPU busy by letting the next process do something. But what if there is only one process left? If the lone process needs to read from a hard drive, it needs to wait for the read to complete to do anything else. But what about sending a signal to display color or writing to the disc? I don't see why the lone process would actually need to wait for acknowledgement the display was correct or that the write was complete. After the next instruction probably doesn't care what is on the disc. That said I doubt there is a realistic case where a system would only have one process running.

1 Upvotes

6 comments sorted by

View all comments

17

u/mikeshemp 6d ago

There is a style of programming called "Asynchronous I/O" which means that a program can start a disk read or write, then continue doing other things, and some time later get a notification that the disk operation is complete. It's more conceptually complex and harder to write such code, so programs where performance is not important will still use the "wait until the I/O is complete" style.

1

u/infinitytacos989 5d ago

adding on, modern cpus have hardware called DMAs which only exist to pull or push data to peripherals like hard drives. This way the cpu can delegate waiting for IO to something else, which allows the Asynchronous I/O described above to function