locking

In Java, what is the difference between a monitor and a lock

守給你的承諾、 提交于 2019-11-30 12:42:52
Using the synchronized keyword method, using the javap command to view the bytecode, it is found that monitor is used, and if it is possible to call the monitor when the synchronized is implemented, is that my understanding, right? Please correct it if you do not. What is the relationship between them? What is the relationship between the lock and the monitor? From the official documentation of Locks and Synchronization ( https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html ): Synchronization is built around an internal entity known as the intrinsic lock or monitor lock

.NET Threading - is lock needed for assignments

ⅰ亾dé卋堺 提交于 2019-11-30 12:35:13
I've got some multi threaded code I'd like to increase the performace of a bit, so I'm wondering if I can get rid of a lock. I've got a field member: private IList<ServerStatus> status; It's updated in a thread like so: status = GetUpdatedStatus(); And it's used in another thread like this: var currentStatus = status; So the question is, can the above yield any problems without locks around the two assignment statements ? I guess the only scenario I can see is currentStatus being null, but then again I'd expect an assignment to be somewhat thread-safe (either it has changed the reference or

How to properly lock a value type?

别等时光非礼了梦想. 提交于 2019-11-30 12:08:05
I was reading about threading and about locking. It is common practise that you can't (well should not) lock a value type. So the question is, what is the recommended way of locking a value type? I know there's a few ways to go about doing one thing but I haven't seen an example. Although there was a good thread on MSDN forums but I can't seem to find that now. Thanks Use another object for the lock. int valueType; object valueTypeLock = new object(); void Foo() { lock (valueTypeLock) { valueType = 0; } } Kent Boogaart Your question is worded in such a way that it suggests to me that you don't

Locking on an interned string?

痴心易碎 提交于 2019-11-30 11:37:54
Update: It is acceptable if this method is not thread safe, but I'm interested in learning how I would make it thread safe. Also, I do not want to lock on a single object for all values of key if I can avoid it. Original Question: Suppose I want to write a higher order function that takes a key and a function, and checks if an object has been cached with the given key. If is has, the cached value is returned. Otherwise, the given function is run and the result is cached and returned. Here's a simplified version of my code: public static T CheckCache<T>(string key, Func<T> fn, DateTime expires)

Can I put a return statement inside a lock

a 夏天 提交于 2019-11-30 11:29:17
Dupe: return statement in a lock procedure: inside or outside The title is a little misleading. I know that you can do it, but I'm wondering about the performance implications. consider these two blocks of code. (no error handling) This block has the return outside of the lock public DownloadFile Dequeue() { DownloadFile toReturn = null; lock (QueueModifierLockObject) { toReturn = queue[0]; queue.RemoveAt(0); } return toReturn; } This block has the return statement within the lock public DownloadFile Dequeue() { lock (QueueModifierLockObject) { DownloadFile toReturn = queue[0]; queue.RemoveAt

View isolation level for a query in mysql

与世无争的帅哥 提交于 2019-11-30 11:24:27
问题 How do I determine the isolation level in use for a given query? After a query is executed (by a 3rd party application) I'd like to know which isolation level was used (e.g., read uncommitted). To be clear, I'm currently working on an application that uses EF4 running against mysql 5.1. I'm try to test different coding patterns to change isolations levels for specific EF4 queries. I need to be able to test and make sure the isolation levels are being set correctly. 回答1: SHOW VARIABLES LIKE

Best way to find SQL Locks in SQL Server 2008

被刻印的时光 ゝ 提交于 2019-11-30 11:11:20
What is the best way to find the SQL locks along wih the user associated with that lock in SQL Server 2008? Remus Rusanu select * from sys.dm_tran_locks will list all current locks, granted or pending, along with the requesting session id. select * from sys.dm_exec_sessions will list all current sessions, including the client host and login name. But going this way is very seldom what you want. For a more digestible form, use the Activity Monitor and watch the blocking as reported there. Carlos Run this against the master db: SELECT spid,blocked,program_name,loginame,hostname,lastwaittype,*

Using the same lock for multiple methods

回眸只為那壹抹淺笑 提交于 2019-11-30 11:03:55
I haven't had any issues using the same lock for multiple methods so far, but I'm wondering if the following code might actually have issues (performance?) that I'm not aware of: private static readonly object lockObj = new object(); public int GetValue1(int index) { lock(lockObj) { // Collection 1 read and/or write } } public int GetValue2(int index) { lock(lockObj) { // Collection 2 read and/or write } } public int GetValue3(int index) { lock(lockObj) { // Collection 3 read and/or write } } The 3 methods and the collections are not related in anyway. In addition, will it be a problem if this

Why is table-level locking better than row-level locking for large tables?

落花浮王杯 提交于 2019-11-30 10:55:44
问题 According to the MySQL manual: For large tables, table locking is often better than row locking, Why is this? I would presume that row-level locking is better because when you lock on a larger table, you're locking more data. 回答1: from the (pre-edit) link Slower than page-level or table-level locks when used on a large part of the table because you must acquire many more locks use a row level lock if you are only hitting a row or two. If your code hits many or unknown rows, stick with table

Git 'fatal: Unable to write new index file'

情到浓时终转凉″ 提交于 2019-11-30 10:52:22
问题 I've seen many of the other threads about this and they don't help. I have a very simple repo - two JavaScript files. I have 100+ GB on Macbook. When I try to move the files into a subdirectory and stage locally the changes I get ... fatal: Unable to write new index file This happens whether I do all actions in terminal or if I use a GUI like SourceTree. Additionally, one of the files becomes locked and I cannot delete the working directory until I log off and back in. Why is this happening?