Search code examples
multithreadingprocesssleepblockingsuspend

what is the difference between block, suspend and sleep


For example, a process is listening on some port with block mode, so if the I/O is not ready, the process will be blocked.

while (true)
{
    msg = recv(port, BLOCKING_FLAG); // blocks here
    cout<<msg<<endl;
}

We also know that we can make a process sleep: sleep(1000).

My question is: if such a process is blocking, can I say that the process is suspended? Will the process be swapped out from CPU? Same questions on sleep.


Solution

  • "Sleeping" -- usually means that the thread is in an explicit sleep(...) call.

    "Suspended" -- sometimes is used in a generic way, meaning that the thread is waiting for ...something. Other times, "Suspended" means that some other thread or process explicitly suspended it (e.g., for debugging purposes), and the process/thread will not be able to run again until it is explicitly resumed.

    "Blocked" -- is the most generic of the three. Often it merely means that the process/thread is waiting for something. Sometimes it implies that what the thread/process is waiting for is an I/O operation.