locking

Object locking private class members - best practice? (Java)

我怕爱的太早我们不能终老 提交于 2020-01-04 02:32:10
问题 I asked a similar question the other day but wasn't satisfied with the response, mainly because the code I supplied had some issues that people focused on. Basically, what is the best practice for locking private members in Java? Assuming each private field can only be manipulated in isolation and never together (like in my Test class example below), should you lock each private field directly (example 1), or should you use a general lock object per private field you wish to lock (example 2)?

Why does the lock insure that the underlying monitor is released and direct usage of monitor does not?

一笑奈何 提交于 2020-01-03 21:04:38
问题 The msdn article Thread Synchronization (C# Programming Guide) specifies that: lock (x) { DoSomething(); } is equivalent to: System.Object obj = (System.Object)x; System.Threading.Monitor.Enter(obj); try { DoSomething(); } finally { System.Threading.Monitor.Exit(obj); } and then that: "Using the lock keyword is generally preferred over using the Monitor class directly, ... because lock insures that the underlying monitor is released, even if the protected code throws an exception " Does this

.NET Threading & Locks & Waiting

一世执手 提交于 2020-01-03 18:02:34
问题 I am attempting to make my GUI thread remain responsive-ish during long running operations. These operations must be synchronous as they are usually operations which are required to finish before the requested operation can complete. I was attempting to do this with a background worker, monitors and a lock object. Essentially I want to start a timer before the long running process is started, start the long running process in the background thread and wait on the background worker thread to

Hadoop datanode fails to start throwing org.apache.hadoop.hdfs.server.common.Storage: Cannot lock storage

三世轮回 提交于 2020-01-03 17:14:21
问题 I have some problems trying to start a datanode in Hadoop, from the log I can see that datanode is started twice (partial log follows): 2012-05-22 16:25:00,369 INFO org.apache.hadoop.hdfs.server.datanode.DataNode: STARTUP_MSG: /************************************************************ STARTUP_MSG: Starting DataNode STARTUP_MSG: host = master/192.168.0.1 STARTUP_MSG: args = [] STARTUP_MSG: version = 1.0.1 STARTUP_MSG: build = https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1

Hadoop datanode fails to start throwing org.apache.hadoop.hdfs.server.common.Storage: Cannot lock storage

一笑奈何 提交于 2020-01-03 17:14:18
问题 I have some problems trying to start a datanode in Hadoop, from the log I can see that datanode is started twice (partial log follows): 2012-05-22 16:25:00,369 INFO org.apache.hadoop.hdfs.server.datanode.DataNode: STARTUP_MSG: /************************************************************ STARTUP_MSG: Starting DataNode STARTUP_MSG: host = master/192.168.0.1 STARTUP_MSG: args = [] STARTUP_MSG: version = 1.0.1 STARTUP_MSG: build = https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1

Calling Thread.Sleep() inside lock statement in .net

杀马特。学长 韩版系。学妹 提交于 2020-01-03 16:55:08
问题 I was wondering if a call to Threa.Sleep on a thread that already acquiered a Monitor will release the lock before going to sleep: object o = new object(); Montior.Enter(o); Thread.Sleep(1000); Monitor.Exit(o); While the thread is suspended - can other thread acquire o ? 回答1: No, the lock will not be released if you Sleep. If you want to release it, use Monitor.Wait(o, timeout) ; further, you can also use this to signal from another thread - another thread can use Monitor.Pulse[All] (while

Is it possible to programatically find out what process is locking a file across a network

我与影子孤独终老i 提交于 2020-01-03 15:22:08
问题 I have a file on a Windows 2003 server which is locked by a process running on another Windows 2003 server. Is it possible to find out which process on which machine is locking this resource. I don't mind which language I use to do this. 回答1: http://technet.microsoft.com/en-us/sysinternals/bb897552.aspx PsFile The "net file" command shows you a list of the files that other computers have opened on the system upon which you execute the command, however it truncates long path names and doesn't

std::lock still caused deadlock

醉酒当歌 提交于 2020-01-03 14:30:05
问题 std::lock is used to prevent deadlock, right? However in my testing, it still caused deadlock. Could you check my test code to see if I used it incorrectly? std::mutex m1; std::mutex m2; void func1() { std::unique_lock<std::mutex> lock1(m1, std::defer_lock); printf("func1 lock m1\n"); std::this_thread::sleep_for(std::chrono::seconds(2)); std::unique_lock<std::mutex> lock2(m2, std::defer_lock); printf("func1 lock m2\n"); std::lock(m1, m2); printf("func1 std lock\n"); } void func2() { std:

Locking to handle concurrency— a good idea? [closed]

我的梦境 提交于 2020-01-03 13:36:21
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . In order to handle concurrency issue, is locking-- any form of locking, whether it's row, table or database locking a good solution? If not, how to handle concurrency issue? 回答1: If you believe Oracle, no, not at all. That's because Oracle went to great lengths to avoid it.

iOS - Concurrent access to memory resources

喜夏-厌秋 提交于 2020-01-03 12:32:13
问题 My app downloads several resources from server, data and data descriptors. These downloads, triggered by user actions, can be performed simultaneously, let's say, up to 50 downloads at a time. All these asynchronous tasks end up creating objects in memory, (e.g. appending leaves to data structures, such as adding keys to mutable dictionaries or objects to arrays). My question is: can this cause stability issues? For instance, if several simultaneous tasks try to add keys to the same