当前位置:网站首页>线程的阻塞问题
线程的阻塞问题
2022-06-24 06:44:00 【ligang2255】
Thread.join是个捣蛋的功能,事实上所有的阻塞都是捣蛋。
只有特殊的底层功能才需要阻塞,比如socket服务等,其他用户级的阻塞功能都是自找麻烦。
解决办法就是共用一个消息(全局变量),在一个可以接受的频率下去查看消息,事实上windows底层的消息循环机制本身就是一个反复查看,根本不存在什么所谓通知,而是有人负重前行,在底层不断查看消息,你在上层才感觉不到查看过程,还以为消息是自己过来的,根本就是有底层代码检查搬运。
所以,用户应用系统也可以设计一个消息机制,借用底层消息系统也可以,不借用更简单。
举个例子:
写个http服务,服务启动后,线程进入listen阻塞状态,此时保留soket为外部变量,线程本身循环检查退出条件,如果条件满足,socket.stop(),如果外部调用stop()也可以终止。
反而是Thread.Abort()并不能中断其内部的soket阻塞,也就不可能在其异常处理中执行soket.stop()。这是个逻辑错误,上层代码不能控制底层。最好的办法反而是最简单的,把阻塞的那个东西放在外部,直接stop,就会停止阻塞,同时也引发了上层调用的异常,线程于是可以正常退出,而不需要使用Abort。
边栏推荐
- 日期、时间库使用备注
- PCL calculates the area of a polygon
- Climbing 10000 NASA pictures about Mars exploration, I found a secret
- Dichotomous special training
- UE常用控制台命令
- Selector (>, ~, +, [])
- 《canvas》之第3章 曲线图形
- Event related | reveal how Ti-One's support ability for large-scale events is developed
- PNAs: Geometric renormalization reveals the self similarity of multi-scale human connectome
- Combine with (& &) logic or (||), dynamic binding and ternary operation
猜你喜欢

【008】表格数据逐行筛选,跳出for循环及跳过本次循环思路_#VBA

More than 60 million shovel excrement officials, can they hold a spring of domestic staple food?

RDD的执行原理

Bjdctf 2020 Bar _ Babystack
![[image fusion] image fusion based on directional discrete cosine transform and principal component analysis with matlab code](/img/21/a5a973f06ea002755a8a2a4431dcd8.png)
[image fusion] image fusion based on directional discrete cosine transform and principal component analysis with matlab code
![[equalizer] bit error rate performance comparison simulation of LS equalizer, def equalizer and LMMSE equalizer](/img/45/61258aa20cd287047c028f220b7f7a.png)
[equalizer] bit error rate performance comparison simulation of LS equalizer, def equalizer and LMMSE equalizer

How to connect the Bluetooth headset to the computer and how to connect the win10 computer to the Bluetooth headset

Blue Bridge Cup seven segment code (dfs/ shape pressing + parallel search)

图形技术之管线概念
![[GUET-CTF2019]zips](/img/79/22ff5d4a3cdc3fa9e0957ccc9bad4b.png)
[GUET-CTF2019]zips
随机推荐
选择器(>,~,+,[])
Deploy L2TP in VPN (Part 2)
Pyhton crawls to Adu (Li Yifeng) Weibo comments
Continue to have a fever. Try the asynchronous operation of dart language. The efficiency is increased by 500%
Combine with (& &) logic or (||), dynamic binding and ternary operation
Win10 build webservice
atguigu----16-自定义指令
chrono 使用备注
Global and Chinese market of basketball uniforms 2022-2028: Research Report on technology, participants, trends, market size and share
atguigu----15-内置指令
PCL calculates the area of a polygon
(CVE-2020-11978)Airflow dag中的命令注入漏洞复现【vulhub靶场】
【Django中运行scrapy框架,并将数据存入数据库】
[pointnet] matlab simulation of 3D point cloud target classification and recognition based on pointnet
图形技术之坐标转换
[image fusion] image fusion based on NSST and PCNN with matlab code
Global and Chinese market of water massage column 2022-2028: Research Report on technology, participants, trends, market size and share
Obtain the package name, application name, icon, etc. of the uninstalled APK through packagemanager. There is a small message
[image feature extraction] image feature extraction based on pulse coupled neural network (PCNN) including Matlab source code
UE common console commands