Alexey,
> Somewhat related: is there a guide to thread safety guarantees of 2.1
> sockets? For example, is it safe to close() the socket from one thread
> if another thread is blocked on recv()/send()? What about poll()? Can
> multiple threads call send() in parallel or they need to be
> synchronized manually?
> These things should probably be documented in the javadocs.
You can migrate a socket from one thread to another. You have to
guarantee the memory barrier when the migration is done.
However, you can never use the same socket from the two threads in
parallel (such as the example you give above).
Martin