Linux基础—多线程实现任务

发表于:2014-10-09 10:17

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:(@_@)ゞ    来源:51Testing软件测试网采编

  这里,我们首先要实现一种数据结构,将相应的任务,线程的fd,还有队列实现。
  声明代码如下:
1 #ifndef _HEAD_H
2 #define _HEAD_H
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <string.h>
7 #include <sys/stat.h>
8 #include <sys/select.h>
9 #include <sys/types.h>
10 #include <fcntl.h>
11 #include <pthread.h>
12 #include <sys/time.h>
13 #include <signal.h>
14 #define MSG_LEN 1024
15 #define TASK_CNT 1024
16 extern pthread_mutex_t lock;
17 extern pthread_cond_t cond1;
18 extern pthread_cond_t cond2;
19 typedef struct tag_fd
20 {
21     int s_rfd;
22     int s_wfd;
23     struct tag_fd *next;
24 }FD,*pFD;
25 typedef struct tag_task
26 {
27     char s_msg[MSG_LEN];
28     int s_fd;
29 }TASK,*pTASK;
30 typedef struct tag_que
31 {
32     TASK arr[TASK_CNT+1];
33     int front;
34     int tail;
35 }QUEUE,*pQUEUE;
36 void fd_insert(pFD *phead,int rfd,int wfd);
37 void fd_init(pFD *phead);
38 int  fd_find(pFD phead,int rfd);
39 void fd_del(pFD *phead,int rfd);
40 void add_task(pQUEUE pq,pTASK pt);
41 void get_task(pQUEUE pq,pTASK pt);
42 void excute_task(pTASK pt);
43 #endif
31/3123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号