While most operating systems have internal locking on sockets, it is not guaranteed everywhere. Because of that, you will always have to live with the possibility that some smart person is able to modify the Linux kernel and remove the locks if they find it appropriate for their distribution. Also, while simultaneous sending and receiving might not be a problem, because of the nature of TCP, disconnecting
and closing (which SFML currently implicitly does) the socket on another thread while you are simultaneously blocking on a receive operation
might cause undefined behaviour. That is already disregarding the fact that TCP has a well-defined connection tear-down mechanism that SFML does not respect, you don't have to make matters worse
.
If you ask me, if you have to make this kind of consideration, you should reconsider the design of your system. Having to rely on operating system side effects
to synchronize your own code is never a good idea. It might seem simple to understand now, but at some point down the road, it will become so complex that you will not know why things don't work as intended any longer, and waste a lot of time debugging. Instead, you should think about making synchronization more explicit between threads. Have a single thread take exclusive care of communication on a socket. Everything that happens to that socket will happen on that thread and no other. This way you don't have to distribute code concerning the same matter over multiple sites and even threads.
This design is probably not scalable, considering that you currently have a thread per socket, but that is a story for another time...