使用而不是&QUOT什么;锁定"当code在多台计算机上运行的声明? [英] What to use instead of the "lock" statement when the code is running on multiple machines?

查看:239
本文介绍了使用而不是&QUOT什么;锁定"当code在多台计算机上运行的声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助 语句确保一个线程不进入code的一个关键部分,而另外一个线程处于临界区。然而,它不会如果工作量为s $ P $垫跨服务器的一个农场工作(例如几的IIS服务器+负载平衡器)。

The lock statement ensures that one thread does not enter a critical section of code while another thread is in the critical section. However, it won't work if the workload is spread across a farm of servers (e.g. a few IIS servers + a load balancer).

.NET是否支持这样的情景?
是否有可用于控制的关键code段由多台计算机上运行的线程的执行任何类?

Does .NET support such a scenario?
Is there any class that can be used to control the execution of a critical code section by threads running on multiple machines?

如果不是,是否有处理此类问题的任何标准方法?

If not, is there any standard method of handling such problems?

这个问题的灵感来自于该开始这里但不限到SharePoint或ASP.NET一个讨论

This question was inspired by a discussion that started here but is not limited to SharePoint or ASP.NET.

推荐答案

如果你有机会到一个集中的SQL Server实例,你可以用它来作为一个分布式的锁协调和使用的 sp_getapplock 和的 sp_releaseapplock 的存储过程。

If you have access to a centralized SQL Server instance, you can use it to act as a distributed lock coordinator and manage the application locks using the sp_getapplock and sp_releaseapplock stored procedures.

在SQL应用程序锁定(或互斥) Server 2005中

这篇关于使用而不是&QUOT什么;锁定"当code在多台计算机上运行的声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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