- 论坛徽章:
- 0
|
- void * recieve_thread(void *args);
- class Server
- {
- public:
- Server() {}
- ~Server() {}
-
- bool setAddr(char *ip, unsigned short port);
-
- void run();
-
- public:
- int max;
-
- private:
- char ip[16];
- unsigned short port;
- pthread_t recv_tid;
- };
- void Server::run()
- {
- pthread_create(&recv_tid, NULL, recieve_thread, this);
-
- return;
- }
- void * recieve_thread(void *args)
- {
- Server *ser = (Server *)args;
-
- while(1)
- {
- recv_line(buf);
-
- max = MAX(max, atoi(buf));
- }
- return(NULL);
- }
复制代码 线程函数和类怎么结合, 多线程程序中主要逻辑都在线程函数内, 访问一个对象还好, 要是访问多个对象呢?
|
|