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

推荐订阅源

G
Google Developers Blog
宝玉的分享
宝玉的分享
月光博客
月光博客
B
Blog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
博客园_首页
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
A
About on SuperTechFans
Y
Y Combinator Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
D
Docker
爱范儿
爱范儿
博客园 - 司徒正美
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net

博客园 - 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();
     }
 }