vs2013使用pthread

注意加这一句

#pragma comment(lib,"x86/pthreadVC2.lib")

https://www.cnblogs.com/lizhigang/p/7326022.html

使用Thread的时候注意容器和值的区别。
以下操作有风险,所有线程的&sClient都是一样的。
创建新的线程的时候都是用的同一个容器。

        sClient = accept(slisten, (SOCKADDR *)&remoteAddr, &nAddrlen); //和客户端 connect()对应
        if (sClient == INVALID_SOCKET)
        {
            printf("accept error !");
            continue;
        }
        char sendBuf[20] = { '\0' };
        printf("接受到一个连接:%s \r\n", inet_ntop(AF_INET, (void*)&remoteAddr.sin_addr, sendBuf, 16));

        ThreadPidTCPServer = new pthread_t[1];;
        ThreadAttrTCPServer = new pthread_attr_t[1];

        CreatThreadVal(ThreadPidTCPServer, ThreadAttrTCPServer);
        pthread_attr_init(ThreadAttrTCPServer);
        pthread_attr_setscope(ThreadAttrTCPServer, PTHREAD_SCOPE_PROCESS);
        pthread_attr_setdetachstate(ThreadAttrTCPServer, PTHREAD_CREATE_DETACHED);
        threadSocket = (SOCKET *)malloc(sizeof(SOCKET));
pthread_create(ThreadPidTCPServer, ThreadAttrTCPServer, StartTCPEcho, &sClient);

你可能感兴趣的:(vs2013使用pthread)