I know for ONE thread (one socket), I cannot perform read() or write() at the same time, or can I?
But what if I create 2 thread and each of them handle read() and write() separately? I don’t know in low level view, will the read() and write() obtain the socket lock, so only one operation is allowed to execute at one time? Will it?
I am using Window as the platform, but also like to know is there different in Unix machine?
I ask this question because I am confused that, why we need non-blocking IO since 2 threads are able to let us read() and write() simultaneously?
Of course not. A thread can only call one method at a time. The question makes no sense.
They don’t need a lock. TCP is full-duplex. You can read and write on the same socket. at the same time.
No.
Make up your mind. First you asked whether it is possible, now you (correctly) say it is.
NIO allows you to handle more than one socket in the same thread. The purpose of this is conservation of threads, for example in servers that have to handle hundreds of thousands of connections.