locking

What's the difference between an exclusive lock and a shared lock?

邮差的信 提交于 2019-12-03 01:30:29
问题 According to wikipedia, Shared locks are sometimes called "read locks" and exclusive locks are sometimes called "write locks". Can you explain the reasoning behind the terms "shared" and "exclusive"? 回答1: I wrote this answer down because I thought this would be a fun (and fitting) analogy: Think of a lockable object as a blackboard (lockable) in a class room containing a teacher (writer) and many students (readers). While a teacher is writing something (exclusive lock) on the board: Nobody

Does MySQL/InnoDB implement true serializable isolation?

匿名 (未验证) 提交于 2019-12-03 01:30:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: It is not entirely clear from MySQL documentation whether the InnoDB engine implements true serializable isolation 1 or snapshot isolation , which is often confusingly called "serializable" too. Which one is it? If MySQL InnoDB doesn't, are there any completely free, production-quality RDBMS which do? 1 where "true serializable isolation" means the absence of not only read anomalies as per the SQL standard, but also the write skew anomaly, explained in further detail here . 回答1: UPDATE: See comments, this seems to be fixed in MySQL 5.5 ,

Is the volatile keyword required for fields accessed via a ReentrantLock?

烂漫一生 提交于 2019-12-03 01:11:12
My question refers to whether or not the use of a ReentrantLock guarantees visibility of a field in the same respect that the synchronized keyword provides. For example, in the following class A , the field sharedData does not need to be declared volatile as the synchronized keyword is used. class A { private double sharedData; public synchronized void method() { double temp = sharedData; temp *= 2.5; sharedData = temp + 1; } } For next example using a ReentrantLock however, is the volatile keyword on the field necessary? class B { private final ReentrantLock lock = new ReentrantLock();

JPA and optimistic locking modes

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I read an article on the blog of Oracle here about JPA and locking modes. I don't understand well the difference between OPTIMISTIC and OPTIMISTIC_FORCE_INCREMENT lock mode types. OPTIMISTIC mode : When an user locks an entity with this mode, a check is done on version field entity ( @version ) at beginning of transaction and a check on version field is also done at end of transaction. If versions are differents, transaction rolls back. OPTIMISTIC_FORCE_INCREMENT mode : When an user choose this mode, he have to flush() state of EntityManager

Possible locking issue in Tkinter application

匿名 (未验证) 提交于 2019-12-03 01:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to create a sliding menubar for my tkinter application, but I've run into an issue that I suspect comes from my not locking a thread properly. While I have been dabbling with Python for a while, I'm relatively new to both tkinter and threaded applications, and I hoped someone here might be able to shed a little light on what I'm doing wrong. My code is as follows: class MenuBar (): def slide_out ( self , event = None ): def helper (): while self . canvas . coords ( self . bg )[ 0 ] > 100 and self . mouseIn : self .

What is (are) difference between NOLOCK and UNCOMMITTED

穿精又带淫゛_ 提交于 2019-12-03 00:59:30
I use SQL Server 2012. I write two queries but what is a different between NOLOCK and UnCommitted ? SELECT lastname, firstname FROM HR.Employees with (READUNCOMMITTED) SELECT lastname, firstname FROM HR.Employees with (NoLock) NOLOCK : Is equivalent to READUNCOMMITTED (source : MSDN ) NOLOCK or READUNCOMMITTED Specifies that dirty reads are allowed. No shared locks are issued to prevent other transactions from modifying data read by the current transaction, and exclusive locks set by other transactions do not block the current transaction from reading the locked data. Allowing dirty reads can

When should I use Scope Locking (Application, Server, etc…) vs named locking in ColdFusion?

匿名 (未验证) 提交于 2019-12-03 00:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When is it appropriate to use <cflock scope="application"> or it's ilk as opposed to <cflock name="foo">? Specifically, I'm interested in using CFLock to protect shared objects in the application, session, or server scopes, but I'm also interested in finding out about different uses of locking in ColdFusion. 回答1: You should use when reading and writing from things that can change in the application scope. For example: <cfquery name="application.myData"> select * from myTable </cfquery> You are going to want to lock that with type="exclusive"

Is the ConcurrentDictionary thread-safe to the point that I can use it for a static cache?

社会主义新天地 提交于 2019-12-03 00:00:53
Basically, if I want to do the following: public class SomeClass { private static ConcurrentDictionary<..., ...> Cache { get; set; } } Does this let me avoid using lock s all over the place? Yes, it is thread safe and yes it avoids you using locks all over the place (whatever that means). Of course that will only provide you a thread safe access to the data stored in this dictionary, but if the data itself is not thread safe then you need to synchronize access to it of course. Imagine for example that you have stored in this cache a List<T> . Now thread1 fetches this list (in a thread safe

What resource does a key lock actually lock?

梦想与她 提交于 2019-12-03 00:00:45
I know a key lock locks a key in an index. However, what does "key" actually mean? For example, if I have a non-clustered index on a surname column and attempt an update where surname = "Jones", will I have effectively locked every row in the table where the surname is "Jones"? Or will the index be locked at a higher level, preventing access of rows with surnames other than "Jones"? The reason I ask is this note in Books Online about Lock Granularity and Hierarchies: KEY: A row lock within an index used to protect key ranges in serializable transactions. This suggests a range of keys will be

Checking whether the current thread owns a lock

懵懂的女人 提交于 2019-12-02 22:41:06
Suppose I have the following code: public class SomeClass() { private readonly object _lock = new object(); public void SomeMethodA() { lock (_lock) { SomeHelperMethod(); //do something that requires lock on _lock } } public void SomeMethodB() { lock (_lock) { SomeHelperMethod(); //do something that requires lock on _lock } } private void SomeHelperMethod() { lock (_lock) { //do something that requires lock on _lock } } } Locking inside SomeHelperMethod seems redundant and wasteful, since all callers have already taken a lock. However, simply removing the lock from SomeHelperMethod seems