当前位置:网站首页>Understanding of C manualresetevent class
Understanding of C manualresetevent class
2022-07-01 06:07:00 【Old sentencing】
ManualResetEvent class
It can notify one or more waiting threads that an event has occurred , Allow threads to communicate with each other by signaling , To control whether threads can access resources
Common grammatical meanings :
- ManualResetEvent manualEvent = new ManualResetEvent(true);// by true(signaled state ), It can be executed from the beginning , Thread cannot be blocked
- ManualResetEvent manualEvent = new ManualResetEvent(false);// by flase(nonsignaled Blocking state ), You can't do it from the beginning
- manualEvent.Reset(); // Set the event state to a non terminating state , Cause threads to block .
- manualEvent.Set(); // Set the event state to the termination state , Allow one or more waiting threads to continue .
- manualEvent.WaitOne (); Block the current thread until another thread calls Set Method , Only ManualResetEvent The state of is blocked (nonsignaled) when ,WaitOne Can really play a role ;

internal class Program
{
private static ManualResetEvent mre = new ManualResetEvent(false);
static void Main(string[] args)
{
Console.WriteLine(" Start at ManualResetEvent Blocking up 3 Threads ");
for (int i = 0; i <= 2; i++)
{
Thread t = new Thread(ThreadProc);
t.Name = "Thread_" + i;
t.Start();
}
Thread.Sleep(500);
Console.WriteLine(" When all three threads are started , Press Enter Key call Set () To release all threads .");
Console.ReadLine();
mre.Set();
Thread.Sleep(500);
Console.WriteLine(" When ManualResetEvent When signaled , call WaitOne() The thread of does not block . Press enter to display this ");
Console.ReadLine();
for (int i = 3; i <= 4; i++)
{
Thread t = new Thread(ThreadProc);
t.Name = "Thread_" + i;
t.Start();
}
Thread.Sleep(500);
Console.WriteLine(" Press Enter Key call Reset(), So the thread is calling WaitOne() It will block again .");
Console.ReadLine();
mre.Reset();
// Start a wait ManualResetEvent The thread of .
Thread t5 = new Thread(ThreadProc);
t5.Name = "Thread_5";
t5.Start();
Thread.Sleep(500);
Console.WriteLine("\nPress Enter to call Set() and conclude the demo.");
Console.ReadLine();
mre.Set();
Console.ReadLine();
}
private static void ThreadProc()
{
string name = Thread.CurrentThread.Name;
Console.WriteLine(name + " Start and call mre.WaitOne()");
mre.WaitOne();
Console.WriteLine(name + " ends.");
}
}边栏推荐
- Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village
- 机械臂速成小指南(六):步进电机驱动器
- Small guide for rapid completion of mechanical arm (VI): stepping motor driver
- UOW of dev XPO comparison
- What if the data in the cloud disk is harmonious?
- MySQL中 in 和 exists 的区别
- [note] e-commerce order data analysis practice
- Pit of kotlin bit operation (bytes[i] and 0xff error)
- He struggled day and night to protect his data
- 基于LabVIEW的计时器
猜你喜欢

3D打印机穿线:5种简单的解决方案

LED lighting used in health lighting

Arcserver password reset (account cannot be reset)

My experience from technology to product manager

Smartinstantiationawarebeanpostprocessor of the extension point series determines which construction method to execute - Chapter 432

JDBC database operation

Primary application case of Excel DuPont analyzer
![kotlin位运算的坑(bytes[i] and 0xff 报错)](/img/2c/de0608c29d8af558f6f8dab4eb7fd8.png)
kotlin位运算的坑(bytes[i] and 0xff 报错)

FPGA - 7系列 FPGA内部结构之Clocking -02- 时钟布线资源

linux 关闭redis 进程 systemd+
随机推荐
jdbc-连接池
穿越派·派盘 + Mountain Duck = 数据本地管理
What if the data in the cloud disk is harmonious?
C language beginner level - realize the minesweeping game
利用百度地图查询全国地铁线路
Enter an expression (expressed as a string) and find the value of this expression.
Linux closes the redis process SYSTEMd+
Flink实战--多流合并
el-table 动态表头渲染 固定第一列 高度问题
FPGA - 7系列 FPGA内部结构之Clocking -01- 时钟架构概述
Send you through the data cloud
DHT11 temperature and humidity sensor
分布式锁实现
让厦门灌口镇田头村变甜头村的特色农产品之一是蚂蚁新村
SOE spatial analysis server MySQL and PostGIS geospatial database of Postgres anti injection attack
论文学习记录随笔 多标签之GLOCAL
C XML help class
ONEFLOW source code parsing: automatic inference of operator signature
69 cesium code datasource loading geojson
Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village