Tag: 互斥锁

rails – 实现一个简单的锁,以防止用户同时编辑相同的数据

我有一个应用程序,我需要阻止用户在由其他用户编辑数据时编辑数据。 我正在考虑最好的方法,并想要提出想法。 到目前为止,我已经创建了一个设置模型,用于在键/值对中存储db上的应用程序范围配置。 所以,对于锁,我有一个名为LOCKED_TABLE_UID的设置实例,它存储了编辑表的用户的user_id,如果表是空的,则为null(nil)。 >> lock = Setting.find_by_key(‘LOCKED_TABLE_UID’) 然后,我在我的应用程序控制器中实现了2个方法来获取和释放锁: # current_user returns the user currently logged in def acquire_lock lock = Setting.find_by_key(“LOCKED_TABLE_UID”) if lock.value # if lock taken, see if it’s the current_user or someone else if lock.value.to_i == current_user.id.to_i return true else return false end else # lock is free, assign it to this […]

Ruby中的线程锁定(使用soap4r和QT)

[编辑注意:注意到我已将互斥锁创建放在构造函数中。 移动它并注意到没有变化。] [编辑注2:我在试运行中将调用更改为app.exec while TRUE do app.processEvents() puts ‘.” end 我注意到,一旦Soap4r服务开始运行,没有再次调用过程事件] [编辑注释3:在这里创建了一个相关的问题: 使用Soap4r在ruby中进行线程锁定 我正在尝试编写一个ruby程序,它接收SOAP命令以在监视器上绘制(从而允许远程监视器访问)。 我已经整理了一个简单的测试应用程序来构思这个想法。 图形工具包是QT。 我有我认为锁定的问题。 我已经添加了调用来测试服务器中显示的代码中的方法。 我正在测试的服务器端是: require ‘rubygems’ require ‘Qt4’ require ‘thread’ require ‘soap/rpc/standaloneserver’ class Box < Qt::Widget def initialize(parent = nil) super setPalette(Qt::Palette.new(Qt::Color.new(250,0,0))) setAutoFillBackground(true) show end end class SOAPServer < SOAP::RPC::StandaloneServer @@mutex = Mutex.new def initialize(* args) super # Exposed methods […]