In non blocking IO programming model, a thread blocked on data available channels, as shown below,
in python,
while True:readers, _, _ = select.select([sys.stdin, sock], [], []) # blocked select()for reader in readers:if reader is sock:print(sock.recv(1000).decode('utf-8'))else:msg = sys.stdin.readline()sock.send(msg.encode('utf-8'))
in java,
public void run() {while(true){try{executeCycle();} catch(IOException e){e.printStackTrace();}try {Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}}}public void executeCycle() throws IOException {takeNewSockets();readFromSockets();writeToSockets();}
In Non-blocking IO programming model, execution flow generally follows the pattern of infinite-loop with the main(only) responsibility to find the data available channels(ready) and perform IO with the available channel.
In a scenario, where all channels are busy(for a duration), Does non-blocking IO programming model allow a thread that perform nio with/without infinite loop also to perform another CPU-bound task in same thread, for a meantime?