select是线程安全的吗?
或者说:
多线程环境下select的行为如何?如:
thread1从socket1检测到read,
而thread2从socket1检测到exception,
结果如何?

解决方案 »

  1.   

    你这是是说SQL的Select 么?跟Socket有什么关系?
      

  2.   

    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在多线程下可以是安全的。
      

  3.   

    zeroxing,好像SQL是有一个SELECT语句哦~哈哈
      

  4.   

    msdn上的描述好象不能说明我的这个问题吧
      

  5.   

    是不是要根据情况?
    我的意思是如果FD_SET是几个线程共用的,应该是不安全的,如果FD_SET是每个线程各自的(虽然FD_SET成相同的socket句柄),应该是安全的