当前位置:网站首页>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.");
}
}边栏推荐
- 讓田頭村變甜頭村的特色農產品是仙景芋還是白菜
- Know the future of "edge computing" from the Nobel prize!
- C# ManualResetEvent 类的理解
- Record currency in MySQL
- 可动的机械挂钟
- SystemVerilog学习-09-进程间同步、通信和虚方法
- three. JS summary
- XAF Bo of dev XPO comparison
- Cjc8988 Low Power Stereo codec with 2 stereo headphone drivers
- Geoffrey Hinton: my 50 years of in-depth study and Research on mental skills
猜你喜欢

不是你脑子不好用,而是因为你没有找到对的工具

数据库问题,如何优化Oracle SQL查询语句更快,效率更高

指数法和Random Forest实现山东省丰水期地表水体信息

Send you through the data cloud

Timer based on LabVIEW

JDBC database operation

Crossing sect · paipan + Siyuan notes = private notebook

Why use huluer pie disk instead of U disk?

Some errors encountered in MySQL data migration

【文件系统】如何在ubi之上运行squashfs
随机推荐
Oracle create user + Role
Highmap gejson data format conversion script
Arcserver password reset (account cannot be reset)
穿越派·派盘 + Mountain Duck = 数据本地管理
68 cesium code datasource loading czml
讓田頭村變甜頭村的特色農產品是仙景芋還是白菜
PLA不粘贴在床上:6个简单的解决方案
Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village
It's not that you have a bad mind, but that you haven't found the right tool
kubeadm搭建kubenetes 集群(个人学习版)
表格中el-tooltip 实现换行展示
Bat operation FTP upload and download command
Flink实战--多流合并
Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village
This is the necessary software for college students 𞓜 knowledge management
穿越派·派盘 + 思源笔记 = 私人笔记本
One of the characteristic agricultural products that make Tiantou village, Guankou Town, Xiamen into a "sweet" village is
kotlin位运算的坑(bytes[i] and 0xff 报错)
three.js小结
Huluer app help