Are threads which are executing blocking system calls awoken by interrupts

interruptschedulingthread

I've been reading a bit about threads and interrupts. And there is a sections which says that parallel programing using threads is simpler because we don't have to worry about interrupts.

However, what is the mechanism in which signals the release of the blocking system call if not an interrupt?

Example

I read i file in my thread which use a blocking system call to read the file from the disk.

During that time, other threads are running.

At some point the file is ready to be read from the hard disk.

Does it notify the processor of this via a hardware interrupt, so that it can do a context switch ti the thread which asked for the file?

Best Answer

Interrupts are handled by the operating system, threads (or processes, for that matter) aren't even aware of them.

In the scenario you paint:

  • Your thread issues a read() system call; the kernel gets the request, realizes that the thread won't do anything until data arrives (blocking call), so the thread is blocked.
  • Kernel allocates space for buffers (if needed), and initiates the "find the block to be read, request for that block to be read into the buffer" dance.
  • The scheduler selects another thread to use the just freed CPU
  • All goes their merry way, until...
  • ... an interrupt arrives from the disk. The kernel takes over, sees that this marks the completion of the read issued before, and marks the thread ready. Control returns to userspace.
  • All goes their merry way, until...
  • ... somebody yields the CPU by one of a thousand reasons, and it just so happens the just freed CPU gets assigned to the thread which was waiting for data.

Something like that, anyway. No, the CPU isn't asigned to the waiting thread when an interrupt happens to signal completion of the transfer. It might interrupt another thread, and execution probably resumes that thread (or perhaps another one might be selected).