Are parallel calls to send/recv on the same socket valid?

前端 未结 3 2008
花落未央
花落未央 2020-11-22 17:24
  1. Can we call send from one thread and recv from another on the same socket?
  2. Can we call multiple sends parallely from different threads on the same socket?
3条回答
  •  逝去的感伤
    2020-11-22 17:49

    The socket descriptor belongs to the process, not to a particular thread. Hence, it is possible to send/receive to/from the same socket in different threads, the OS will handle the synchronization.

    However, if the order of sending/receiving is semantically significant, you yourself (respectively your code) have to ensure proper sequencing between the operations in the different threads - as is always the case with threads.

提交回复
热议问题