当前位置:网站首页>Deep understanding Net (2) kernel mode 4 Summary of kernel pattern constructs
Deep understanding Net (2) kernel mode 4 Summary of kernel pattern constructs
2022-06-30 13:49:00 【Cucumbers need programming】
In depth understanding of .Net The construction mode of thread synchronization in ( Two ) Kernel mode construction
Preface
Kernel-mode Constructs Generally translated as kernel mode construction ,
Constructs It is both a noun and a verb , But the translation for construction feels a bit like a verb , I think it's better to translate it into a noun , After all s Of , It means multiple , Verbs obviously can't express more than one , Such as kernel mode constructs , Kernel mode constructs .
Environmental statement
IDE:Visual Studio 2022
OS:Win10
.NET:.Net4.6.1
One 、 The advantages of kernel mode
Ahead of us 3 The first section briefly introduces three common constructs of a kernel construct , Now let's talk about why we use kernel constructs ? Advantages of kernel constructs ?
An important advantage of kernel mode is that it can synchronize threads across processes ( We restrict our application to only one program )
Compared to the user mode spin , Kernel mode constructs block threads
You can synchronize between managed threads and local threads
Can be based on EventWaitHandleSecurity Perform certain thread access control
Two 、 Code writing
1. be based on EventWaitHandle Transform a simple lock
The code is as follows ( Example ):
public sealed class EventLock : IDisposable
{
private readonly EventWaitHandle m_available;
public EventLock()
{
m_available = new EventWaitHandle(true,EventResetMode.AutoReset,"testEvent"); // Initially free
}
public void Enter()
{
Int32 currentThreadId = Thread.CurrentThread.ManagedThreadId;
Console.WriteLine($" Threads ID:{
currentThreadId},{
DateTime.Now}, Blocking wait start ");
// Block in kernel until resource available
m_available.WaitOne();
Console.WriteLine($" Threads ID:{
currentThreadId},{
DateTime.Now}, Blocking waiting for completion ");
}
public void Leave()
{
// Let another thread access the resource
m_available.Set();
}
public void Dispose()
{
m_available.Dispose();
}
}
2. test InterProcessLockTest The effect of cross thread locking
The code is as follows ( Example ):
internal class Program
{
static void Main(string[] args)
{
new InterProcessLockTest().TestStart();
Console.ReadLine();
}
}
public class InterProcessLockTest
{
public void TestStart()
{
Console.WriteLine(" InterProcessLockTest TestStart Start !");
IntObj intObj = new IntObj();
EventLock eventLock = new EventLock();
eventLock.Enter();
Console.WriteLine($"get lock,{
DateTime.Now}");
Thread.Sleep(1000*30);
Console.WriteLine($"wait 30s,{
DateTime.Now}");
Console.WriteLine(" InterProcessLockTest TestStart END !");
}
}
Let's finish the editing first , Get into debug Run the console program directly under the directory , You can see the following 
And then it starts visual studio Debugging interface 
We can analyze the code to know , After acquiring a lock , We will not release the lock , At this time, we restart a program ( Can be seen as a process ), At this time , The process could not acquire the lock , Because there is no lock release in another process .
This is cross process synchronization
边栏推荐
- Today's sleep quality record 80 points
- navicat数据库建表是没有utf8选项。
- MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video
- 点击table的td单元格出现dialog弹窗,获取值后将值放回td单元格
- 步骤详解 | 助您轻松提交 Google Play 数据安全表单
- 深入理解.Net中的线程同步之构造模式(二)内核模式2.内核模式构造物Semaphone
- 提权扫描工具
- Data Lake (11): Iceberg table data organization and query
- PG Basics - logical structure management (table inheritance, partition table)
- Directory related commands
猜你喜欢
![[deep anatomy of C language] storage principle of float variable in memory & comparison between pointer variable and](/img/3d/5d7fafba4ff7903afbd51d6d58dcdf.png)
[deep anatomy of C language] storage principle of float variable in memory & comparison between pointer variable and "zero value"

Pytorch查看模型参数量和计算量

【科学文献计量】外文文献及中文文献关键词的挖掘与可视化

防火墙基础之总部双机热备与分支基础配置

DeFi“钱从哪来”?一个大多数人都没搞清楚的问题

Read all the knowledge points about enterprise im in one article

Introduction to two types of rxjs observable operators

Observable, reliable: the first shot of cloudops series Salon of cloud automation operation and maintenance

Assertions of regular series

损失函数:DIOU loss手写实现
随机推荐
香港回归20余年,图扑数字孪生港珠澳大桥,超震撼
Directory related commands
This editor will open source soon!
Prometheus 2.29.0 new features
(8) JMeter component detailed once only controller
ABAP toolbox v1.0 (with implementation ideas)
Basic syntax of unity script (3) - accessing game object components
60 divine vs Code plug-ins!!
STM32 porting the fish component of RT thread Standard Edition
Hangzhou E-Commerce Research Institute: the official website (website) is the only form of private domain
A keepalived high availability accident made me learn it again!
一篇文章读懂关于企业IM的所有知识点
半导体动态杂谈
Embedded development: five C features that may no longer be prohibited
This article explains the concepts of typed array, arraybuffer, typedarray, DataView, etc
数据库表为什么写不进数据了
“即服务”,企业数字化转型的必然选择
【刷题篇】避免洪水泛滥
可观测,才可靠:云上自动化运维CloudOps系列沙龙 第一弹
Prometheus 2.29.0 新特性