locking

c# xml.Load() locking file on disk causing errors

Hi all, I have a simple class XmlFileHelper as follows: public class XmlFileHelper { #region Private Members private XmlDocument xmlDoc = new XmlDocument(); private string xmlFilePath; #endregion #region Constructor public XmlFileHelper(string xmlFilePath) { this.xmlFilePath = xmlFilePath; ...

When can lock(syncObject) throw an exception?

I have written a com component in .NET and if I try to take a lock on any object in any method (that is invoked by unmanaged code talking to my com component) I get an exception. I do not have the exact text of the exception at this moment but it wasn't much helpful either. So my question is under what circumstances a lock(syncObject) ...

Multiple-instances lock?

I am using a mysql db. Right now for my multithreads i use lock(staticVar){...}. It works fine. But i can add data via the command line which also uses the DB. It will occasionally throw an exception or cause my main instance to throw an exception from the sqlite db being lock. How can i create a mutli instance lock so i no longer get t...

Locks in Synchronized Blocks.

I just need a confirmation that i have understood the concept of locks in synchronized blocks correctly. First I will tell what I have understood. Acquiring a lock of an object means that no other thread can access the synchronized code of the object's class. In case of synchronized methods, Threads acquire lock on the object used to inv...

ADO Connection to Access leaves .ldb file behind

I'm writing an MS Outlook (2003) macro which uses an ADO Connection to an Access DB (2003). I am simply opening a connection, getting some records into a Recordset, which I use to populate a grid (but not bind to). I then close the Recordset and Connection and set both to Nothing. Not rocket science is it? But I am getting an infuriatin...

Does lock allocate

I read somewhere, although I can't remember where, that using the lock keyword in C# can allocate. I know that trying to lock a ValueType will box the valuetype, but are there any other situations? EDIT:: Everyone seems to be answer the valuetype case, I already know this! I also know what locks are and how to use them in great depth...

Using request.getSession() as a locking object?

I have some java code that gets and sets a session attribute: Object obj = session.getAttribute(TEST_ATTR); if (obj==null) { obj = new MyObject(); session.setAttribute(obj); } In order to make this code thread-safe, I'd like to wrap it in a synchronized block. But what do I use as the locking object? Does it make sense to use th...

how to prevent opening serial port on linux by foreign application?

In case of "bug" in port driver using locking is not acceptable. ...

file lock leases via NFS v4 in C

does anybody know how to use the fancy file locking features of NFS v4? (described in e.g. About the NFS protocol (scroll down)). supposedly NFS v4 supports file lock leasing with a 45 second lifetime. I would like to believe that the linux kernel (I'm using gentoo 2.6.30) happily takes care of these details, and I can use fcntl() and it...

run command/script when lock/unlock windows station?

Hi, I have Windows 7 pro at work. my problem is i keep on forgetting to clock in/clock out (using the intranet timesheet system). is there a way to run a script or command to automatically open the timesheet page each time i lock/unlock my station? tyvm. ...

Upgradeable read/write lock Win32

I am in search of an upgradeable read write lock for win32 with the behaviour of pthreads rwlock, where a read lock can be up- and downgraded. What I want: pthread_rwlock_rdlock( &lock ); ...read... if( some condition ) { pthread_rwlock_wrlock( &lock ); ...write... pthread_rwlock_unlock( &lock ); } ...read... pthread_rwlock...

Mysql deadlock explanation needed

I received the following deadlock log via "SHOW INNODB STATUS". Can someone care to explain why the transaction was aborted? It seems that Transaction 2 is holding the lock, but is also stuck requesting the same lock (except for the "waiting" part), which leads to a deadlock when Transaction 1 requires it as well. ======================...

Can locking a List fail

I have a class that inherits from MemoryStream in order to provide some buffering. The class works exactly as expected but every now and then I get an InvalidOperationException during a Read with the error message being Collection was modified; enumeration operation may not execute. My code is below and the only line that enumerate...

Deleting rows cause lock timeout

I keep getting these errors when trying to delete rows from a table. The special case here is that i may be running 5 processes at the same time. The table itself is an Innodb table with ~4.5 million rows. I do not have an index on the column used in my WHERE clause. Other indices are working as supposed to. It's being done within a tr...

tempdb SQL Server locking

Hello! Our application runs alongside another application on a customers machine. We have put some efforts regarding avoiding long-running locks in tempdb since this obviously affects concurrency badly. The other application, however does things like: begin transaction create #Table(...); insert into #Table(....) values(...

C# lock on integer ?

Hi, I have a producer/consumer process. The consumed oject as an ID property (of type integer), I want only one object with the same ID to be consumed at a time. How can I perform this ? Maybe I can do something like this, but I don't like it (too many objects created while only one or two with the same ID a day can be consumed and the...

Why are locks performed on separate objects?

Possible Duplicate: Difference between lock(locker) and lock(variable_which_I_am_using) In all of the "thread-safe" code examples i've seen, they lock on a separate dummy object. Why cant locks be directly performed on the data in question? ...

Typical usage scenario to using the ReaderWriterLockSlim property count fields.

I've recently upgraded to ReaderWriterLockSlim for an app i'm writing from the much fatter ReaderWriterLock and apparently more prone to deadlock situations. I see for the new slim lock, there are a number of count properties which can show current read counts, waiting write count, waiting read count. Is their is standard usage scenar...

Java double checked locking by forcing synchronization twice, Workable?

I've read all about how double checked locking fixes never work and I don't like lazy initialization, but it would be nice to be able to fix legacy code and such a problem is too enticing not to try to solve. Here is my example: private int timesSafelyGotten = 0; private Helper helper = null; public getHelper() { if (timesS...

Locking critical section in object used across multiple threads

I've got a class that is instantiated within any number of threads that are spooled up as needed. This means that any number of instantiated versions of this class can be used at any one time, and there's a portion of this class that needs to be locked to prevent concurrent access. To prevent data issues between the various threads, I ...