locking

Double checked locking Article

Hi all, I was reading this article about "Double-Checked locking" and out of the main topic of the article I was wondering why at some point of the article the author uses the next Idiom: Listing 7. Attempting to solve the out-of-order write problem public static Singleton getInstance() { if (instance == null) { ...

Using lock on the key of a Dictionary<string, object>

I have a Dictionary<string, someobject>. EDIT: It was pointed out to me, that my example was bad. My whole intention was not to update the references in a loop but to update different values based on differnt threads need to update/get the data. I changed the loop to a method. I need to update items in my dictionary - one key at a time...

When would I use AutoResetEvent and ManualResetEvent instead of Monitor.Wait/Monitor.Pulse in .net?

They both seem to fulfil the same purpose. When would I chose one over the other? ...

What is the best way for me to implement record locking?

Hi, I have a question about locking. This doesn't have to be only about record locking, but anyway. Let's say I'm writing a web accessible CMS. I am struggling with some ideas. I could, on the moment when a user opens an article for editing, flag the article as being 'in use'. so far so good. but when do I remove the flag? when the us...

How do I use an arbitrary string as a lock in C++?

Let's say I have a multithreaded C++ program that handles requests in the form of a function call to handleRequest(string key). Each call to handleRequest occurs in a separate thread, and there are an arbitrarily large number of possible values for key. I want the following behavior: Simultaneous calls to handleRequest(key) are serial...

Application Object and Concurrency Concerns

In some asp tutorials, like this, i observe the following pattern: Application.Lock 'do some things with the application object Application.Unlock However, since web pages can have multiple instances, there is an obvious concurrency problem. So my questions are the following: What if one page tries to lock while the obje...

Making locking easier in MTAs

In multi-threaded code, when an instance may be read or written by multiple threads, they need to be locked on to perform these operations safely. To avoid the repetition of creating an object to lock on and writing a bunch of lock statements through code, I've created a generic class to handle the locking. Am I missing anything, conc...

What is the best way to open a file for exclusive access in Python?

What is the most elegant way to solve this: open a file for reading, but only if it is not already opened for writing open a file for writing, but only if it is not already opened for reading or writing The built-in functions work like this >>> path = r"c:\scr.txt" >>> file1 = open(path, "w") >>> print file1 <open file 'c:\scr.txt',...

Recursive Lock (Mutex) vs Non-Recursive Lock (Mutex)

POSIX allows mutexes to be recursive. That means the same thread can lock the same mutex twice and won't deadlock. Of course it also needs to unlock it twice, otherwise no other thread can obtain the mutex. Not all systems supporting pthreads also support recursive mutexes, but if they want to be POSIX conform, they have to. Other APIs ...

"read lock failed" at cvs annotate

I am trying to use cvs annotate. This is the what I run: cvs -d /mycvs/cvsroot/ annotate "projects/dg/SomeClass.java" However, I get the following error: cvs annotate: failed to create lock directory for `/mycvs/cvsroot/projects/dg^M' (/mycvs/cvsroot/projects/dg^M/#cvs.lock): No such file or directory cvs annotate: failed to obtain d...

Locking Executing Files: Windows does, Linux doesn't. Why?

I noticed when a file is executed on Windows (.exe or .dll), it is locked and cannot be deleted, moved or modified. Linux, on the other hand, does not lock executing files and you can delete, move, or modify them. Why does Windows lock when Linux does not? Is there an advantage to locking? ...

Ajax keep=alive a good idea?

I'm currently working on a simple CRUD application. One requirement is preventing users from editing things concurrently. In order to do this I "lock" records to see if they're being edited, to prevent other users from editing at the same time. I was thinking a good way of implementing this might be to use an AJAX keep-alive to see if th...

SQL procedure running time widely divergent

I have an application that runs a huge stored procedure on SQL Server 2000. Usually it takes about 1 minute to complete, but occasionally it will take MUCH longer. Just now I ran it three times in a row in my test system. It took 1:12, 1:23, and 55:25. What would cause that behavior? There are other things going on in the database, so I...

What is lock escalation?

I was asked this question at an interview and had no answer. Can anyone here explain? ...

OpenQuery to DB2/AS400 from SQL Server 2000 causing locks

Every morning we have a process that issues numerous queries (~10000) to DB2 on an AS400/iSeries/i6 (whatever IBM calls it nowadays), in the last 2 months, the operators have been complaining that our query locks a couple of files preventing them from completing their nightly processing. The queries are very simplisitic, e.g Select [Fie...

Looking for a recommendation on record-locking within a distributed system

We're trying to come up with a recommended design pattern for our team when it comes to record locking. The typical school of thought goes something like this: 1. User picks a record from a list 2. Lock the record with the user id 3. Load the locked record record (no lock, then someone beat ya to it). Am I missing something, or does th...

Why does AbstractQueuedSynchronizer interrupt on acquring lock

I was looking at the source code of java.uti.concurrent.locks.AbstractQueuedSynchronizer and the acquire() method looks something like this - public final void acquire(int arg) { if (!tryAcquire(arg) && acquireQueued(addWaiter(Node.EXCLUSIVE), arg)) Thread.currentThread().interrupt(); } Why does it interrupt the t...

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

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. ...

Effect of NOLOCK hint in SELECT statements

I guess the real question is: If I don't care about dirty reads, will adding the with (NOLOCK) hint to a SELECT statement affect the performance of: the current SELECT statement other transactions against the given table Example: Select * from aTable with (NOLOCK) ...

Virus scanners locking and deleting temporary files - best way to cope with them?

My application deals with e-mails coming from different sources, e.g. Outlook and IMAP mailboxes. Before parsing them, I write them to the temporary directory (keeping them in memory is not an option). While parsing, I might be writing attachments to the temp directory (for example, if they are too large to keep in memory or for full-tex...