【发布时间】:2011-03-15 07:59:01
【问题描述】:
请你帮我提醒一下最简单的并行编程技术之一。
如何在 C# 中执行以下操作:
初始状态:
semaphore counter = 0
线程 1:
// Block until semaphore is signalled
semaphore.Wait(); // wait until semaphore counter is 1
线程 2:
// Allow thread 1 to run:
semaphore.Signal(); // increments from 0 to 1
它不是互斥体,因为没有临界区,或者你可以说有一个无限临界区。那是什么?
【问题讨论】:
标签: c# concurrency semaphore parallel-processing