惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
Y
Y Combinator Blog
I
InfoQ
美团技术团队
罗磊的独立博客
B
Blog RSS Feed
GbyAI
GbyAI
小众软件
小众软件
IT之家
IT之家
Engineering at Meta
Engineering at Meta
Blog — PlanetScale
Blog — PlanetScale
V
V2EX
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
MyScale Blog
MyScale Blog
博客园 - 聂微东
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss

博客园 - Shapley

项目心得 进程间通讯方式 C#使用MCP协议调用大模型示例 SQL Server LEAD函数实践 sql server行专列一例 数据库字段排序方法两则 Sql Server生成ULID例子 审批流进化记 winform+Task+async 献丑贴:Task.Run中foreach优化 Sql Server Begin TRY sample No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.ValidateAntiforgeryTokenAuthorizationFilter' has been registered. 某低代码平台自定义控件技术点 Element-plus的el-date-picker控件动态切换中英文方案 Chrome浏览器无法查看页面跳转前的请求日志及解决办法 element-plus上传视频并生成缩略图(封面)方案 JWT自动刷新草案 Ajax方法POST的两种提交方式 H5项目在微信浏览器运行实录 Sql Server变量声明及使用技巧 修改Dify的Nginx对外访问端口 Task with Console(with SemaphoreSlim) Task实战 asp.net core 9.0发布centos7.9 CountdownEvent
Barrier
Shapley · 2024-10-23 · via 博客园 - Shapley
 internal class Program
 {
     static bool isOutput = true;
     static int index1 = 0;
     static int index2 = 100;
     static Barrier barrier = new Barrier(2, b =>
     {
         if (index1 == index2)
         {
             Console.WriteLine($"index1与index2相同,比对结束。");
             isOutput = false;
         }
         else
         {
             Console.WriteLine($"index1与index2不同!~");
         }
     });
     static void Main(string[] args)
     {
         var t = Task.Run(() => {
             while (isOutput)
             {
                 index1 = index1 + 2;
                 Console.WriteLine("index1:" + index1);
                 barrier.SignalAndWait();
             }
         });
         var t2 = Task.Run(() =>{
             while (isOutput)
             {
                 index2++;
                 Console.WriteLine("index2:" + index2);
                 barrier.SignalAndWait();
             }
         });

         Console.ReadLine();
     }
 }