Search code examples
c++multithreadingblocking

how to return from a blocked call?


is it possible to force a thread to return from a call to a blocking function such as a blocking read from a stream ?

int x;
std::cin >> x;

for example...


Solution

  • No, it's not possible. If you want to find out whether there's data to read, use the select() syscall - if you only read when there's data waiting, you'll never block