【发布时间】:2012-08-06 02:02:10
【问题描述】:
我正在编写一个 pthreading 网络应用程序(用 C 语言),并且正在考虑我应该创建一个线程来处理每个传入连接。但是,我不知道应该使用哪种设计,因为我必须将连接数限制为固定数量(例如 5)。
在阅读 pthread_join 的手册页时,我发现:
There is no pthreads analog of waitpid(-1, &status, 0), that is, "join with any terminated
thread". If you believe you need this functionality, you probably need to rethink your
application design.
这是为什么?我怎样才能实现我的目标? 谢谢
【问题讨论】:
-
您是否考虑过只在您的套接字上使用非阻塞 I/O(可能使用 poll、epoll 或 select)并且只为所有连接使用一个线程?使用这种方法,您绝对可以扩展超过 5 个连接 - 这并不难。
标签: c linux unix networking pthreads