当前位置:网站首页>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.");
}
}边栏推荐
- Crossing sect · paipan + Siyuan notes = private notebook
- Oracle 序列+触发器
- Preliminary level of C language -- selected good questions on niuke.com
- OpenGL es: (2) relationship between OpenGL es, EGL and glsl
- Pla ne colle pas sur le lit: 6 solutions simples
- excel可视化
- DHT11 temperature and humidity sensor
- TiDB单机模拟部署生产环境集群(闭坑实践,亲测有效)
- pycharm 配置jupyter
- Skywalking integrated Nacos dynamic configuration
猜你喜欢

Diagramme dynamique Excel

He struggled day and night to protect his data

How to add a gourd pie plate

Cjc8988 Low Power Stereo codec with 2 stereo headphone drivers

Preliminary level of C language -- selected good questions on niuke.com

OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)

蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是

讓田頭村變甜頭村的特色農產品是仙景芋還是白菜

68 cesium code datasource loading czml

Primary application case of Excel DuPont analyzer
随机推荐
Differences between in and exists in MySQL
srpingboot security demo
4GB大文件,如何实时远程传输和共享?
OpenGL ES: (1) OpenGL ES的由来 (转)
It's not that you have a bad mind, but that you haven't found the right tool
DEV XPO对比之XAF BO
excel可视化
LED lighting used in health lighting
OpenGL ES: (2) OpenGL ES 与 EGL、GLSL的关系
蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是
Send you through the data cloud
Freeswitch dial the extension number
无限水平大理石游戏
Code shoe set - mt3114 · interesting balance - explain it with examples
pycharm 配置jupyter
Index method and random forest to realize the information of surface water body in wet season in Shandong Province
Fixed height of the first column in El table dynamic header rendering
linux 关闭redis 进程 systemd+
Timer based on LabVIEW
Flink实战--多流合并