聊天室-线程池-tcp

聊天室-线程池-tcp

项目介绍

​ 客户端

​ 1、注册昵称 2、发送消息|接收消息 3、创建登录,注册界面(待补充)

​ 服务端

​ 1、等待客户端连接 2、接收客户端信息 3、通知所有人xxx进入了聊天室 4、接收其他所有消息 5、xxx退出了聊天室

基础准备

​ 这里用到了network和pthreadpool的工具

queue.h

#ifndef QUEUE_H
#define QUEUE_H
#include <stdbool.h>

//基本的队列结构体
typedef struct Queue
{
   
	void** arr;
	int cal;
	int front;
	int rear;
}Queue;

// 创建队列
Queue* create_queue(int cal);

// 销毁队列
void destroy_queue(Queue* queue);

// 入队
void push_queue(Queue* queue,void* arg);

// 出队
void pop_queue(Queue* queue);

// 队空
bool empty_queue(Queue* queue);

// 队满
bool full_queue(Queue* queue);

// 队头
void* front_queue(Queue* queue);

// 队尾
void* rear_queue(Queue* queue);
#endif//QUEUE_H

pthreadpool.h

#ifndef THREADPOOL_H
#define THREADPOOL_H
#include "queue.h"
#include <pthread.h>

//定义一个线程入口函数
typedef void (*EnterFP)(void*);

//定义线程池结构体
typedef struct ThreadPool
{
   
	//线程数量
	int thread_cnt;
	//线程id
	pthread_t* tids;
	//存放线程的仓库(队列)
	Queue* store;
	//线程的入口函数
	EnterFP enter;
	//定义几个加锁,条件变量
	pthread_mutex_t hlock;
	pthread_mutex_t tlock;
	pthread_cond_t empty;
	pthread_cond_t full;
}ThreadPool;

//线程池的创建
ThreadPool* create_threadpool(int thread_cnt,int store_cal,EnterFP enter);

//线程池的启动
void start_threadpool(ThreadPool* thread);

//生产
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值