linux操作系统编程——线程的应用

程序功能:

       程序分成两个部分,一个写端一个读端,采用fifo进行进程间的通信,写端负责写入命令,读端负责读命令,读端采用多线程的方式进行编写程序,创建两个线程,一个唤醒线程用于唤醒发送线程,一个发送线程用于发送消息;主线程读取命令后,将命令添加到任务队列中,唤醒线程进行判断,如果任务队列为空则睡眠,否则唤醒发送线程,采用条件变量与互斥锁进行线程间的同步互斥;


程序如下:

(1)、pthread_read.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <fcntl.h>

struct node
{
    int cmd;
    struct node *next;
};

struct node *head;
char buf[100];

pthread_mutex_t send_mutex, wake_mutex;
pthread_cond_t send_cond, wake_cond;

struct node *create_list(void);
void insert_list(struct node *, int );
void delete_list(struct node *, int );
int is_empty_list(struct node *);
int get_list_cmd(struct node *
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值