locking

Blocking write locks with transacted NTFS

According to the MSDN documentation, transactional NTFS doesn't seem to allow one to block on opening a file for write - instead the open operation fails with ERROR_SHARING_VIOLATION. I'd like to block on writes instead - how can I do this? Ideally I'd like the following properties for the solution: Works over a network share (so no l...

Does using a lock has better performance than using a local (single application) semaphore ?

Does using a lock has better performance than using a local (single application) semaphore? I read this blog from msdn : Producer consumer solution on msdn and i didn't like their solution to the problem because there are always 20 elements left in the queue. So instead, i thought about using a Semaphore that will be available only in...

Visual studio 2010 locking issue when developing user controls

I researched quite a lot on this but finally seemed to pin down on this issue. Visual Studio some times randomly locks the build dll/exe file if you have custom controls in your project. Steps to replicate: Create a winforms app/dll project Add a new class, say CustomButton that inherits from Button Build Create a form. Look in the too...

Release Lock when form close

Hi. I have a form which have System.Threading.Timer which is updating after 1 sec. In timer tick method i have a list on which i acquire lock first the extract data from list and display it in the Grid view. problem is this when I close the form, application hangs sometime. In form closing i am using following statement to close the...

Select-locking in Rails with MySQL

Looking for a best-practice advice: Let's suppose I have a Account object with limit attribute. Each day there can be n Payments, with sum of their amounts up to the account limit. When creating a new payment, it checks to see if it's amount + amounts of other payments of the day are still within the account limit, and either saves the ...

Cross-process read-write synchronization primative in .NET?

Is there a read/write locking mechanism that works across processes (similar to Mutex, but read/write instead exclusive locking)? I would like to allow concurrent read access, but exclusive write access. ...

Locking to modify static value-type member. Is it necessary?

I have a CacheHelper class to facilitate interaction with the cache. I want to use a static int field to specify my cache timeout. The field is initially set to a const default value but I want to provide a way for the application to change the default timeout value. Do you need to lock when modifying a static value type? Is the lock i...

What's the functioning scope of an critical section locker in c++?

// locks a critical section, and unlocks it automatically // when the lock goes out of scope CAutoLock(CCritSec * plock) The above is from wxutil.h, does it lock the access of different process , or just locks different threads in the same process? ...

Why spinlock in linux kernel is in the ".subsection 1" (or ".text.lock.smth")?

Hello In linux kernel in the implementation of spinlocks, e.g. http://lxr.linux.no/#linux+v2.6.18/include/asm-i386/semaphore.h#L97 97static inline void down(struct semaphore * sem) 98{ 99 might_sleep(); 100 __asm__ __volatile__( 101 "# atomic down operation\n\t" 102 LOCK_PREFIX "decl...

Synchronizing NSMutableArray for Thread Security ?

HI All, I have a Threaded application, in which there is a NSMutableArray, which contains the NSManagedObjects, Now i want my array to be accessed once at a time by any Thread. So how do i synchronize that array, or may be put locking mechanism on it. Thanks in Advance ... ...

Forcing closed an open file by C#

I found a similar question here but it was closed/accepted with an answer of "don't do that". I'm in a situation where I don't care what happens to the other applications, I want to take a file that may be locked by others (rudely if needed) and have my way with it. I may need to move, rename, or delete this file. Basically I need to ...

NHibernate, TransactionScope and locking

I am trying to use TransactionScope with NHibernate in order to call several methods in one transactions. Data repository methods are like this: public virtual void Save(T dataObject) { try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = I...

How to set read lock and write lock in directshow application?

To apply a general lock, I can do this: CAutoLock(CCritSec * plock) But how can I set read and write lock respectively? ...

How to cause locks to be freed in one thread which were set by another

I have a simple thread pool written in pthreads implemented using a pool of locks so I know which threads are available. Each thread also has a condition variable it waits on so I can signal it to do work. When work comes in, I pick a thread by looking finding an available thread from the lock pool. I then set a data structure associate...

Diagram or other way to describe analysing threading vulnerabilities?

I'm working on a complex data structure, think of it as an OODBMS storing single-user CAD info, and want a way to explain vulnerability points to justify where I'm locking and the scope of the critical sections that are being used. IO is via memory-mapping to files that are potentially opened multiple times in different threads. You cou...

Access Chrome History through JDBC

Hi all, I'm trying to connect to the chrome history database (sqlite) via a java application and run some queries in read only mode. I'm using sqlite.jar but when I connect, I get the following error: org.tmatesoft.sqljet.core.SqlJetException: BUSY: error code is BUSY I know some applications can access the file without copying it first ...

Java: Do all mutable variables need to be volatile when using locks?

Does the following variable, x, need to be volatile? Or does the manipulation within a utils.concurrent lock perform the same function as a synchronized block (ensuring it's written to memory, and not stored in cpu cache)? myMethod(){ myLock.lock(); x++; myLock.unlock(); } ...

Two transactions seem to block each other but none of them is waiting

I have two transactions running in a mysql database, neither of which seems to make any progress. Both hold some locks but as far as I understand they don't conflict. Both transactions are in state "ACTIVE" (I would have expected that one of them be in a waiting state if it were blocked by the other). I've attached the "TRANSACTIONS" ...

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

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 ("monito...

Is there a way to check if a NSLock was acquired?

Hi, I am working on multithreaded code. Data access is locked in several sections via "NSLock" objects. I want to ensure that some methods which are called within these sections check if their appropriate lock was aquired. Something like: assert([myLock isSet] == YES); I can't find something like "isSet" in NSLock. Any ideas how to ...