Does printf () call a short-term scheduler to schedule another process in the finished queue?

When a process tries to print to the console (using printf), it falls under an I / O event, where it will be sent to the wait queue, and therefore the short-term scheduler takes effect and selects another process CPU time Does the context switch turn on here, on the console output event ?

+3
source share
2 answers

Of course, it is possible, yes, if the I / O stream is blocked by another stream that performs the output.

Do not use what you mean by "short-term planner." The console thread is likely to be protected by the mutex and blocked / unlocked by threads in the "normal" way when they request I / O.

+1
source

You will need to perform manual synchronization. You cannot assume that it is thread safe. If you want individual threads to not access the stream at the same time, you need to wrap the output with a mutex.

0
source

All Articles