创建线程不接受成员函数 [英] Create thread is not accepting the member function

查看:125
本文介绍了创建线程不接受成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为网络编程创建一个类。这将创建一个通用的套接字与线程。

I am trying to create a class for network programming. This will create a general purpose socket with thread.

但是当我试图克隆线程使用createthread()。第三个参数产生错误。从网络我知道,我不能使用成员函数作为参数的createthread()。

But when I tried to crete the thread using createthread(). The third argument is producing errors. And from the net I came to know that I can't use the member functions as an argument to the createthread().

有任何事情,我可以实现

Is there any thing by which I can achieve this?

推荐答案

在迷失的时候,我得到了,事实是,在 CreateThread socket 那么就没有麻烦了。因为 CreateThread 套接字 。但是,如果您传递为具有套接字的对象,则套接字 不小心<

At lost I got it, the very fact is, in CreateThread if you pass the socket then there is no trouble. Because CreateThread is taking care of that socket. But if you pass as an object which is having that socket, then CreateThread is not taking care of the socket, and it is ends up in invalid socket in the new thread.

下面成功的代码

The successed code below

SOCKET s=socket(....);
bind(s,...);
listen(s,...);
SOCKET temp=accept(s,(sockaddr *)&addrNew,&size);
DWORD threadId;
HANDLE thread=CreateThread(NULL,0,&MyThreadFunction,(LPVOID)(temp),0,&threadId);

这篇关于创建线程不接受成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆