locking

java.lang.IllegalMonitorStateException: (m=null) Failed to get monitor for

[亡魂溺海] 提交于 2019-11-29 22:54:00
Why may this happen? The thing is that monitor object is not null for sure, but still we get this exception quite often: java.lang.IllegalMonitorStateException: (m=null) Failed to get monitor for (tIdx=60) at java.lang.Object.wait(Object.java:474) at ... The code that provokes this is a simple pool solution: public Object takeObject() { Object obj = internalTakeObject(); while (obj == null) { try { available.wait(); } catch (InterruptedException e) { throw new RuntimeException(e); } obj = internalTakeObject(); } return obj; } private Object internalTakeObject() { Object obj = null;

Git 'fatal: Unable to write new index file'

守給你的承諾、 提交于 2019-11-29 22:44:13
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? Is the lock preventing something from staging? If so, what/how do I unlock the problem file on OS X??

We need to lock a .NET Int32 when reading it in a multithreaded code?

两盒软妹~` 提交于 2019-11-29 22:25:30
I was reading the following article: http://msdn.microsoft.com/en-us/magazine/cc817398.aspx "Solving 11 Likely Problems In Your Multithreaded Code" by Joe Duffy And it raised me a question: "We need to lock a .NET Int32 when reading it in a multithreaded code?" I understand that if it was an Int64 in a 32-bit SO it could tear, as it is explained in the article. But for Int32 I imagined the following situation: class Test { private int example = 0; private Object thisLock = new Object(); public void Add(int another) { lock(thisLock) { example += another; } } public int Read() { return example;

On linux, how to make sure to unlock a mutex which was locked in a thread that dies/terminates?

a 夏天 提交于 2019-11-29 22:07:19
问题 This is an interview question. On linux, how to make sure to unlock a POSIX mutex which was locked in a POSIX thread that dies/terminates? My idea: Linux will release it automatically when it send kill or termination signal to the program ? But, I cannot find more details about how OS do this ? thanks 回答1: A robust mutex can be used to handle the case where the owner of the mutex is terminated while holding the mutex lock, so that a deadlock does not occur. These have more overhead than a

How to check if a table is locked in sql server

江枫思渺然 提交于 2019-11-29 21:50:00
I have a large report I am running on sql server. It takes several minutes to run. I don't want users clicking run twice. Since i wrap the whole procedure in a transaction, how do I check to see if the table is locked by a transaction? If so I would want to return an error message saying "report generating, please try again in a few minutes". How can this be accomplished? Better yet, consider sp_getapplock which is designed for this. Or use SET LOCK_TIMEOUT Otherwise, you'd have to do something with sys.dm_tran_locks which I'd use only for DBA stuff: not for user defined concurrency. You can

Locking with S3

烈酒焚心 提交于 2019-11-29 21:35:03
What's the recommended way to implement a simple locking mechanism to be used in conjunction with S3? Example of what I want to do: acquire lock by object id read object from S3 modify data write object to S3 release lock Ideally looking for a cloud based locking mechanism. I could use memcached locally, but then I have to deal with scaling that. I don't see an obvious way to implement lightweight locking with any AWS APIs, but it seems like a common problem. I wonder if you could use SimpleDB to do an atomic acquire lock operation. Has anyone tried that? Ok, I spent some time this morning

Parallel.ForEach with adding to list

亡梦爱人 提交于 2019-11-29 21:17:56
I'm trying to run multiple functions that connect to a remote site (by network) and return a generic list. But I want to run them simultaneously. For example: public static List<SearchResult> Search(string title) { //Initialize a new temp list to hold all search results List<SearchResult> results = new List<SearchResult>(); //Loop all providers simultaneously Parallel.ForEach(Providers, currentProvider => { List<SearchResult> tmpResults = currentProvider.SearchTitle((title)); //Add results from current provider results.AddRange(tmpResults); }); //Return all combined results return results; }

What's the right pattern for waiting on a file lock to be released?

落爺英雄遲暮 提交于 2019-11-29 21:12:20
问题 I need to open a file but if it's currently not available I need to wait until it's ready. What's the best approach to take? SCENARIO I'm using files as a persistent caching mechanism for application data. This data needs to be read and deserialized often (written only once, and deleted occasionally). I have a cleanup process that runs on a separate thread that determines which files are no longer needed and deletes them. Opening and reading of files may happen concurrently (rarely, but could

In Java what is the performance of AtomicInteger compareAndSet() versus synchronized keyword?

梦想与她 提交于 2019-11-29 20:58:21
I was implementing a FIFO queue of requests instances (preallocated request objects for speed) and started with using the "synchronized" keyword on the add method. The method was quite short (check if room in fixed size buffer, then add value to array). Using visualVM it appeared the thread was blocking more often than I liked ("monitor" to be precise). So I converted the code over to use AtomicInteger values for things such as keeping track of the current size, then using compareAndSet() in while loops (as AtomicInteger does internally for methods such as incrementAndGet()). The code now

How long will a C# lock wait, and what if the code crashes during the lock?

自古美人都是妖i 提交于 2019-11-29 20:45:34
i saw the following code, and i wanted to use it for a simple activity which may only be executed one at a time, and won't occur frequently (so the chance of occuring twice at a time is very small, but you never know). So the code: //class variable private static object syncRoot = new object(); //in a method: lock (syncRoot) { DoIt(); } when another thread comes by and wants to execute the code, how long will it wait until the lock is released? for ever, or can you somehow set a timeout? and second: if the DoIt() method throws an exception, is the lock still released? when another thread comes