c语言多线程收发数据,c语言多线程队列读写

本文介绍了使用C语言实现一个简单的多线程队列服务,包括主函数、队列结构和相关操作函数。通过创建多个线程进行数据放入队列,并从队列中取出数据,展示了如何在多线程环境下处理并发读写操作。
摘要由CSDN通过智能技术生成

最近用c语言写了个简单的队列服务,记录一下,文件结构为 main.c queue.c queue.h,代码如下:

主函数

#define NUM_THREADS 200

#include

#include

#include

#include

#include

#include

#include

struct threadArgs

{

struct queue *q;

char *c ;

};

void* putArg(void *params)

{

struct threadArgs *args = params;

putQueue(args->q, args->c);

}

int main()

{

pthread_t tids[NUM_THREADS]; //线程id

struct queue * g_q;

g_q = initQueue();

char c[LENTH] = "test\0";

char b[LENTH] = "btest\0";

char a[LENTH] = "atest\0";

char *h = "";

;

; i < NUM_THREADS; ++i ) {

struct threadArgs *args;

args = (struct threa

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值