多线程用select的安全问题?

LinHanLao 2004-11-26 04:07:57
select是线程安全的吗?
或者说:
多线程环境下select的行为如何?

如:
thread1从socket1检测到read,
而thread2从socket1检测到exception,
结果如何?
...全文
350 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sharkhuang 2004-11-26
  • 打赏
  • 举报
回复
select是线程安全的
qrlvls 2004-11-26
  • 打赏
  • 举报
回复
未明白?如何不安全?
barsteng 2004-11-26
  • 打赏
  • 举报
回复
是不是要根据情况?
我的意思是如果FD_SET是几个线程共用的,应该是不安全的,如果FD_SET是每个线程各自的(虽然FD_SET成相同的socket句柄),应该是安全的
LinHanLao 2004-11-26
  • 打赏
  • 举报
回复
msdn上的描述好象不能说明我的这个问题吧
danyueer 2004-11-26
  • 打赏
  • 举报
回复
zeroxing,好像SQL是有一个SELECT语句哦~哈哈
danyueer 2004-11-26
  • 打赏
  • 举报
回复
The parameter writefds identifies the sockets that are to be checked for writability. If a socket is processing a connect call (nonblocking), a socket is writeable if the connection establishment successfully completes. If the socket is not processing a connect call, writability means a send, sendto, or WSASendto are guaranteed to succeed. However, they can block on a blocking socket if the len parameter exceeds the amount of outgoing system buffer space available. It is not specified how long these guarantees can be assumed to be valid, particularly in a multithreaded environment.

上文来自MSDN,我们可以知道select在多线程下可以是安全的。
zeroxing 2004-11-26
  • 打赏
  • 举报
回复
你这是是说SQL的Select 么?跟Socket有什么关系?

18,363

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧