多线程12-ManualResetEventSlim
2024-08-30 09:23:05
class Program
{
static ManualResetEventSlim manualRestEvnetSlim = new ManualResetEventSlim(false);
static void TravelThroughGates(string threadName,int second)
{
Console.WriteLine("{0} falls to sleep", threadName);
Thread.Sleep(TimeSpan.FromSeconds(second));
Console.WriteLine("{0} waits for the gate open", threadName);
manualRestEvnetSlim.Wait();
Console.WriteLine("{0} enter the gates", threadName);
} static void Main()
{
var t1 = new Thread(() => TravelThroughGates("T1", ));
var t2 = new Thread(() => TravelThroughGates("T2", ));
var t3 = new Thread(() => TravelThroughGates("T3", ));
t1.Start();
t2.Start();
t3.Start();
Thread.Sleep(TimeSpan.FromSeconds());
Console.WriteLine("the Gates is open");
manualRestEvnetSlim.Set();
Thread.Sleep(TimeSpan.FromSeconds());
manualRestEvnetSlim.Reset();
Console.WriteLine("the gate has been closed");
Thread.Sleep(TimeSpan.FromSeconds());
Console.WriteLine("the gates opend second times");
manualRestEvnetSlim.Set();
Thread.Sleep(TimeSpan.FromSeconds());
Console.WriteLine("the gates closed angin");
manualRestEvnetSlim.Reset(); }
}
最新文章
- 【VC++技术杂谈007】使用GDI+进行图片格式转换
- Lua 学习笔记(八)错误(error)
- linux和windows下的自动ftp脚本(shell bat)
- 关于闭包的理解(JS学习小结)
- css大牛的博客
- PHP 7 值得期待的新特性(上)
- GotFocus和PreviewLeftButtonDown事件
- Codeforces2B - The least round way(DP)
- MyEclipse8.5注册码生成
- 操作系统层面聊聊BIO,NIO和AIO (epoll)
- k8s 安装步骤
- 【vue】如何在 Vue-cli 创建的项目中引入 iView
- this 关键字 详解
- java提供类与cglib包实现动态代理
- div+css ie6图片之间有间隙的问题
- http中的get和post的区别
- JMeter连接数据库(查询出的数据作为参数)
- bash登录过程 其实还不太了解,先码后看
- 【题解】洛谷P1073 [NOIP2009TG] 最优贸易(SPFA+分层图)
- [css]margin-top重叠
热门文章
- ubuntu不能登陆
- VMware使用自带工具vmware-vdiskmanager精简占用磁盘空间
- DevExpress ASP.NET Core Controls 2019发展蓝图(No.6)
- 【bzoj4552】【Tjoi2016&;Heoi2016】【NOIP2016模拟7.12】排序
- git clone项目失败,Host key verification failed.
- JSON提取器
- 51nod1820 长城之旅
- C#项目类型分三种,Dos(控制台),c/s(客户端与服务器),b/s(浏览器/服务器)
- Linux 安装R包
- 手写Tomcat源码