首页 \ 问答 \ synchronized vs ReentrantLock用于无竞争锁定(synchronized vs ReentrantLock for uncontended locks)

synchronized vs ReentrantLock用于无竞争锁定(synchronized vs ReentrantLock for uncontended locks)

对于完全无竞争的锁定获取,ReentrantLock如何针对synchronized执行?

假设您打算实现一个两个锁定类(这意味着您需要2个不同的锁并且同步不足,就像在LinkedBlockingQueue中那样),其中put和take锁的获取由thread1和thread2(总是)完成,其中意味着锁是无竞争的,并且线程局部性的原理进入,ReentrantLock如何对同步执行(这将需要完全锁定队列)?


How does the ReentrantLock perform against synchronized for a solely uncontended lock acquisition ?

Suppose you intend to implement a two lock class (which means you need 2 different locks and synchronized would not suffice, like that in LinkedBlockingQueue) where in the acquisition of put and take locks are done by say thread1 and thread 2 (always), which means the locks are uncontended and the principle of thread locality comes in, how does the ReentrantLock perform against synchronized(which would entail complete locking of the queue) ?


原文:https://stackoverflow.com/questions/11698418
更新时间:2023-04-20 06:04

最满意答案

我不知道这是不是最好的方法,但这就是我解决这个问题的方法。

在调用InitializeComponent()之后,我在构造函数方法中添加了代码来设置MainForm.cs文件中每个控件的Text属性,如下所示:

public MainForm() {
    InitializeComponent();

    this.Text = Car.UpdateDialog_Title;
    lblLine1.Text = Car.UpdateDialog_lblLine1;
    lblLine2.Text = Car.UpdateDialog_lblLine2;
    butOk.Text = Car.Common_OK;
}

这很有效。 我还将表单的Localizable属性设置为false ,因为该程序没有自己的本地化资源。


I don't know if this is the best way, but this is how I addressed the issue.

I added code to set the Text property of each control in the MainForm.cs file, in the constructor method, after the call to InitializeComponent(), like this:

public MainForm() {
    InitializeComponent();

    this.Text = Car.UpdateDialog_Title;
    lblLine1.Text = Car.UpdateDialog_lblLine1;
    lblLine2.Text = Car.UpdateDialog_lblLine2;
    butOk.Text = Car.Common_OK;
}

This works. I also set the Localizable property for the form back to false, since the program doesn't have its own localization resources.

相关问答

更多
  • 我认为你的目标应该是拥有“品牌化”的资源文件; 你基本上是本地化你的应用程序,除了你只有几个不同的英语版本。 您可以使用ResGen.exe和ResourceManager加载外部资源文件,因此您可以使用5个不同的“资源”文件,但保持代码基础相同。 这篇文章可能也有帮助... http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b388c700-0e07-452b-a19e-ce02775f78a6/ 编辑:顺便说一句,我会第 ...
  • 尝试在主void中将此添加到您的服务中 AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { // do your logging here, wr ...
  • 好。 在VB.net中,您有一个登录表单的模板。 只需添加/新项目,选择“登录表单”。 但这只是创建一个包含两个文本框,用户名和密码的对话框。 每个人都可以做到这一点。 然后由您决定如何验证输入的用户名和密码是否为有效用户,数据库,加密文本文件,注册表中的加密字符串或xml文件或您想要的任何内容。 在生成的表单中还有一些信息: ' TODO: Insert code to perform custom authentication using the 提供了用户名和密码'(请参阅http://go.mic ...
  • 您使用了错误的名称,“global ::”未出现在清单资源名称中。 如果您将资源添加到项目并将其Build Action设置为“Embedded Resource”,则典型名称为project .test.png。 为避免猜测名称,请使用Ildasm.exe并在清单中找到.mresource。 但是,您的名字建议您在Project + Properties,Resources选项卡中添加资源。 好主意,自动生成资源的属性名称。 您将使用项目 .Properties.Resources.test来引用它。 你 ...
  • 为应该在.NET框架上运行的应用程序运行resgen.exe或al.exe ,必须确保.NET 2.0运行时可以读取生成的程序集。 程序集格式已在.NET 4中进行了扩展,因此2.0运行时可以加载4.0程序集。 因此,请确保您使用的是C:\Windows\Microsoft.NET\Framework\v2.0.50727两种工具,而不是来自较新的框架版本。 When running resgen.exe or al.exe for an application that should run on .NE ...
  • 我不知道这是不是最好的方法,但这就是我解决这个问题的方法。 在调用InitializeComponent()之后,我在构造函数方法中添加了代码来设置MainForm.cs文件中每个控件的Text属性,如下所示: public MainForm() { InitializeComponent(); this.Text = Car.UpdateDialog_Title; lblLine1.Text = Car.UpdateDialog_lblLine1; lblLine2.Te ...
  • 你应该使用Geckofx 此外,您需要确保geckofx版本与正确的xulrunner / firefox版本完全匹配。 GeoLocation在geckofx中还没有很好的C#包装类,但您可以使用xpcom C#interops访问它。 var instance = Xpcom.CreateInstance("@mozilla.org/geolocation/provider;1"); Credit goes to the answer by Al ...
  • 是的,你可以通过循环迭代资源。 例如,使用foreach循环: foreach (var res in Application.Current.Resources) { Console.WriteLine(res); } 更新: 要从外部库中获取所有ResourceDictionary'ies ,首先应该加载库,然后获取ManifestResourceInfo 。 让我举个例子: string address = @"WpfCustomControlLibrary.dll"; List
  • 这是一个疯狂的文本墙,所以你有点失去了我。 而且,说实话,当我看到你打算在你打算分发的二进制文件中有一个硬编码的密钥时,我就停止了认真阅读...但是你应该问自己有两个问题: 您的应用程序是否可能如此成功以至于对它有足够的需求,以便拥有相应技能的人倾向于撤销它并发布keygen和/或盗版版本? 并且你不应该花时间更好地为应用程序添加很酷的功能而不是许可代码,这些代码不会改善应用程序本身吗? 别误会我的意思。 我全都是因为人们为他们的工作获得报酬而且我并不反对那些许可他们软件的人; 事实上,我所参与的其中一个项 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。