locking

Cross-Process Locking in C#

I've written an API that will be used on the same box in (1) a windows service, (2) a web application, and (3) a windows forms application. They all need to share a very small set of common data (a few ints, a date, and a string that I could put as properties of a single class). What sort of locking mechanism can I use cross-process so...

Lock Properties File in Java

Hello, I am using the java properties file construct. At the beginning I read it to populate a dialog, but I also give the users the ability to change the values in the dialog and click save. This causes me to call the setProperty method of the properties file. Now, since this webapp can exist over multiple browsers, all changing the sa...

how efficient is locking an unlocked mutex? how much does a mutex costs?

Hi, In a low level language (C, C++ or whatever): I have the choice in between either having a bunch of mutexes (like what pthread gives me or whatever the native system library provides) or a single one for an object. How efficient is it to lock a mutex? I.e. how much assembler instructions are there likely and how much time do they t...

how efficient is a try_lock on a mutex?

Possible Duplicate: how efficient is locking an unlocked mutex? how much does a mutex costs? How efficient is a try_lock on a mutex? I.e. how much assembler instructions are there likely and how much time are they consuming in both possible cases (i.e. the mutex was already locked before or it was free and could be locked). ...

How to lock a file to a thread when serializing?

I'm building a generic xml repository that uses a datacontractserializer to serialize/deserialize the files and I'm unsure as how to ensure that the files cannot be altered when they are being read. My code to read all files is like this: public IQueryable<T> All<T>() where T : class, new() { List<T> instances = ...

Adding objects to queue without interruption

I would like to put two objects into a queue, but I've got to be sure the objects are in both queues at the same time, therefore it should not be interrupted in between - something like an atomic block. Does some one have a solution? Many thanks... queue_01.put(car) queue_02.put(bike) ...

SQL Server - How to lock a table until a stored procedure finishes

I want to do this: create procedure A as lock table a -- do some stuff unrelated to a to prepare to update a -- update a unlock table a return table b Is something like that possible? Ultimately I want my SQL server reporting services report to call procedure A, and then only show table a after the procedure has finished....

C# Object Pooling With Interlocked.Increment

I have seen many good object pool implementations. For example: http://stackoverflow.com/questions/2510975/c-object-pooling-pattern-implementation. But it seems like the thread-safe ones always use a lock and never try to use Interlocked.* operations. It seems easy to write one that doesn't allow returning objects to the pool (just ...

Do NHibernate's transactions slow down other ADO.NET connections?

We're (slowly) moving an application (with a classic ADO.NET DAL) to NHibernate (following both "one-session-per-request pattern" and "repository pattern"). The application, right now, is in a hybrid state (I know, it's horrorful): some query are made by disposable DAO objects (that open a connection in their constructors and dispose ...

WMI hardware locking limitations

What are the limitations of using WMI services for hardware locking purposes? Wouldn't it be better to use this approach? http://www.codeproject.com/KB/mcpp/DriveInfoEx.aspx What do you think? ...

Read uncommitted isolation level doesn't allow to read entries

Hello. I need to read dirty entries in Sql server but I don't understand why I can't. Hope you will help. I have two tabs in management studio with following code Tab 1: SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED GO BEGIN TRAN UPDATE decision.tRequests SET IsComplete = 0 WAITFOR DELAY '00:00:25.000' COMMIT TRA...

Multiprocess conditional/named Lock

In a multiprocess program I want to lock certain function based on arguments e.g. def calculate(spreadsheet): _do_calc(spreadsheet) Now what I want to do is based on spreadsheet, lock the function so that multiple spreadsheets can be worked on concurrently but two calls on same spreadsheet will lock e.g. def calculate(spreadsheet...

jpa 2 hibernate setting a lock on EntityManager.find

Hi guys: a little strange problem.. I'm doing a few testcases on an hibernate project: when I call EntityManager em = getEntityManager(); em.find(Foo.class, 1) I get the entity as I expect, but when I invoke: EntityManager em = getEntityManager(); em.find(Foo.class, 1, LockModeType.WRITE) I'm getting null. Also, w...

Synchronize Read Write Collection in .NET

I have an object which holds a collection of items. I want to be able to add items to the collection through an AddItem method and also to go through all of the items in the collection. My object must be thread safe. I am using a ReaderWriterLockSlim to assure proper synchronization. How should I synchronize the GoThroughAllItems method?...

jpa2 hibernate, a testcase to test lock over an entity

Hi!, I'm using Hibernate 3.5.5.Final and JPA2 How can make a testcase to test if the hibernate lock is working? I wrote this, but seems that the test not pass in the current hibernate version (works fine in the previous version) @Test(expected=OptimisticLockException.class) public void testLock() { EntityManager em = getEntityMa...

Java -Check if file is in print Queue / In Use

Hey SO OK I have a program that: Creates a temporary file based on a users input Prints the File(Optional) Deletes the File (Optional) My problem sits between stages 2&3, I need to wait for the file to finish printing until I can delete it. FYI: the printing will take 5-10 minutes (large file to spool on an old computer) So I nee...

Recursive / nested locking in C# with the lock statement

Possible Duplicate: Re-entrant locks in C# I've looked here on StackOverflow and on MSDN, and can't believe that I couldn't find this question lingering out there on the internets. Let's say I have a class with a private member that I want to access in several public methods. These public methods will be called by different ...

Coding Style: lock/unlock internal or external?

Hello, Another possibly inane style question: How should concurrency be locked? Should the executor or caller be responsible for locking the thread? e.g. in no particular language... Caller::callAnotherThread() { _executor.method(); } Executor::method() { _lock(); doSomething(); _unlock(); } OR Caller::callAnothe...

c# multithreading - Is there a need to lock when writing to DB?

Hi All, I've got a multithreaded C# 2.0 app where each thread writes some results into a SQL server 2000 database table. There is only a straight INSERT command and no other logic. My question is - do I need to put a lock around the methods that writes the results to the database? There is a lock at the moment but I suspect that it's s...

why does `try_lock`s performance behaves always like `lock`on a mutex?

On a mutex: I was asking about the performance of lock here and about the performance of try_lock here. The question about try_lock was closed as exact duplicate to the one about lock. However, I fail to see why try_lock must behave in the same way as lock in every possible mutex implementation. As this question was not really answered...