F
F
Fen1xL2021-10-10 13:45:59
linux
Fen1xL, 2021-10-10 13:45:59

Why use the poll system call to wait for an event from the driver?

There is a process thread that calls the driver's read in a loop. Why use the poll function with a timeout before calling read. Thus, spending some time "reloading" the poll function if a timeout occurs. Why not immediately block the thread with a read call and wait until the data is available, thereby not wasting precious processor cycles (the only option that comes to mind is when you need to force the thread to be slammed and if you use a timeout, then you do not need to interrupt the system call, although if forcibly terminate the thread, then the kernel, in theory, will itself interrupt the system call)? Is this true, maybe something else?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2021-10-11
@Fen1xL

Why not immediately block the thread with a call to read and wait until the data is available

If the stream only reads, then indeed, at first glance, there is no need to call poll.
(only one option comes to mind when it is necessary to forcefully kill the thread and if you use a timeout, then you do not need to interrupt the system call, although if you force the thread to end, then the kernel, in theory, will interrupt the system call itself)

If a system call is stuck in a wait in a driver, then the driver decides whether the wait is interruptible or not. Maybe the driver implements the poll operation with the possibility of interruption, and read - without.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question