简体   繁体   English

在套接字上并行读/写

[英]Parallel read/write on socket

Does it make sense to both write and read on a socket ( SOCK_STREAM ) in parallel with multiple threads? 在与多个线程并行的套接字( SOCK_STREAM )上进行读写都有意义吗? On Linux. 在Linux上。 Do those syscalls block each other? 这些系统调用是否互相阻塞?

Yes, it makes sense. 是的,这很有道理。 Since they are in separate threads they do not block each other. 由于它们位于单独的线程中,因此它们不会相互阻塞。

It makes sense as long as there is exactly one writer and one reader thread. 只要有一个作者和一个读者线程,就有意义。 If you have more than one reader thread you need to lock reading if you have more than one writer thread you have to lock writing. 如果您有多个读取器线程,则需要锁定读取;如果您有多个写入器线程,则必须锁定写入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM