什么是互斥和信号灯在C#中?在这里我们需要实现? [英] What is the Mutex and semaphore In c#? where we need to implement?

查看:251
本文介绍了什么是互斥和信号灯在C#中?在这里我们需要实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是互斥和信号灯在C#中?在这里我们需要实现?

What is the Mutex and semaphore in C#? Where we need to implement?

如何能与他们多线程我们的工作?

How can we work with them in multithreading?

推荐答案

您应该MSDN开始。

  • System.Threading.Mutex: A synchronization primitive that can also be used for interprocess synchronization.
  • System.Threading.Semaphore: Limits the number of threads that can access a resource or pool of resources concurrently.

一般只使用一个互斥跨进程,如如果你有多个应用程序必须共享,或者如果你想建立一个单一实例化的应用程序(即只允许1份在同一时间运行)的资源。

Generally you only use a Mutex across processes, e.g. if you have a resource that multiple applications must share, or if you want to build a single-instanced app (i.e. only allow 1 copy to be running at one time).

信号量可以限制访问并发线程的具体数量,这样你可以有,例如,最多两个线程同时执行特定的代码路径。

A semaphore allows you to limit access to a specific number of simultaneous threads, so that you could have, for example, a maximum of two threads executing a specific code path at a time.

这篇关于什么是互斥和信号灯在C#中?在这里我们需要实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆