- 论坛徽章:
- 0
|
按照参考书写一个多线程并发服务器程序,以下是相关代码:
- .........
- /* Called by pthread_create() */
- void *start_routine(void *arg);
- struct ARG
- {
- int connfd;
- struct sockaddr_in client;
- };
- ......
- main()
- {
- pthread_t thread;
- struct ARG *arg;
- ......
- arg = new ARG;
-
- arg->;connfd=connectfd;
- memcpy((void *)&arg->;client,&client,sizeof(client));
- if(pthread_create(&thread,NULL,start_routine,(void *)arg))
- {
- perror("Pthread_create() Error:");
- exit(1);
- }
- ........
- }
- void* start_routine(void *arg)
- {
- struct ARG *info;
- info=(struct ARG *)arg;
- /* the function handle client's requirement */
- process_cli(info->;connfd,info->;client);
- delete arg;
- pthread_exit(NULL);
-
- }
复制代码
编译的时候说new和delete没有定义
后来我分别换成malloc和free,编译通过,运行时提示段错误
用gdb察看了一下,是程序中参数arg的free有问题
请问如何解决这个问题?谢谢 |
|