当前位置:网站首页>Libevent and multithreading
Libevent and multithreading
2022-07-24 07:01:00 【lifei_ 0001】
First, in the process ,libevent One of the base It's actually a while loop , When the system kernel catches the event , It will capture these events according to the priority of events , Handle with the callback function at the time of registration . How to use it with multithreading ? I think there are two solutions .
One 、 Will monitor accept And connections connect Register with a base On , When an event triggers , Open a new thread to process the received data .
Two 、 Use 1+N Threads , One per thread base.
1 A listening thread , He is only responsible for monitoring connections . When a new client connects , The socket Hand it over to a thread . The polling strategy can be adopted here .
N Threads that handle client business , Each thread is only responsible for its own client time . Threads do not interfere with each other . Each thread should have a pair of pipes , Business thread listens to read time , The listening thread is when there is a new client connection , take socket Write to the queue of a business thread , And write operations to the pipeline of this thread , To trigger the pipeline multi event of this thread , Then the thread knows that a new client needs its own service , Get out of the queue socket, And listen for read Events .
边栏推荐
猜你喜欢

Ge port: sgmii mode and SerDes mode

(静态,动态,文件)三个版本的通讯录

渗透学习-SQL注入篇-靶场篇-安全狗的安装与绕过实验(后续还会更新)

Redis special data type hyperloglog

Record the pits encountered in the deserialization of phpserializer tool class

在线问题反馈模块实战(十二):实现图片删除功能

Three level classification / menu query tree structure
![[lvgl] API functions for setting, changing and deleting styles of components](/img/55/f25a510cf04caff7ee15e72360c3a1.png)
[lvgl] API functions for setting, changing and deleting styles of components

Thinking of data analysis -- analyzing the retail industry as a whole -- an all-round and multifaceted detailed analysis

记录PHPSerializer工具类反序列化遇到的坑
随机推荐
济南人社已签1W+电子劳动合同,法大大助力HR数字化
Lambda expressions sort list objects in multiple fields
《大厂面试》之JVM篇21问与答
【学习笔记】url输入到页面展现中发生了什么?
上传图片base64
Can you increase muscle without exercise??? Just get an injection of hibernating black bear serum
渗透学习-SQL注入篇-靶场篇-安全狗的安装与绕过实验(后续还会更新)
Huawei experts' self statement: how to become an excellent engineer
[lvgl (3)]
[lvgl (2)]
HashSet转数组
项目问题积累
STM32 ADC based on Hal library uses DMA multi-channel sampling and solves the problems encountered
PostgreSQL date handler usage
An AI plays 41 games, and the comprehensive performance score of Google's latest multi game decision transformer is twice that of dqn
tensorflow boolean_ Mask function
Redis入门
Mac解决 Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)问题
【学习笔记】从汇编看 a+++a与 a+a++的区别
Camera Hal OEM module ---- CMR_ grab.c