locking

c# locking

Hello, I am trying to prevent data races in a multihreaded server. My problem is the following: there is a List<RServer>, the type RServer is a class with several fields. Now, the server has several threads all running at the same time and they can modify both the List (adding more items) and the individual RServer instances (changing th...

Locking to handle concurrency-- a good idea?

In order to handle concurrency issue, is locking-- any form of locking, whether it's row, table or database locking a good solution? If not, how to handle concurrency issue? ...

mysql replication - table locking?

I am currently working for a company that has a website running mysql/php (all tables are also using the MYISAM table type). We would like to implement replication, but I have read in the mysql docs and elsewhere on the internet that this will lock the tables when doing the writes to the binary log (which the slave dbs will eventually r...

Removing file locks

I need to recover form an error case where a file gets left in a locked state. How can I in c# tell this file to reset it's locks? I need to add to this the file is opened by a 3rd party dll and I don't actually have access to the file handle. ...

How to access a file with the least amount of locking

in my application (c# 3.5) there are various processes accessing a single xml file (read and write) very frequently. the code accessing the file is placed in an assembly referenced by quite a couple of other applications. for example a windows service might instanciate the MyFileReaderWriter class (locatied in the previously mentioned as...

Overcoming "It is being used by another person or program."

Is there a way to unlock Windows files without downloading a utility? I have a few files on my Windows XP C: drive that are very old and very useless. When I try to delete these files I get the following message: Cannot delete FILENAME.zip: It is being used by another person or program Close any programs that might be using the file...

Command-line tool for finding out who is locking a file

I would like to know who is locking a file (win32). I know about WhoLockMe, but I would like a command-line tool which does more or less the same thing. I also looked at this question, but it seems only applicable for files opened remotely. ...

How can I write a conditional lock in C#?

The thing is I've been using the lock statement to protect a critical part of my code, but now, I realize I could allow concurrent execution of that critical code is some conditions are met. Is there a way to condition the lock? ...

Reader/Writer Locks in C++

I'm looking for a good reader/writer lock in C++. We have a use case of a single infrequent writer and many frequent readers and would like to optimize for this. Preferable I would like a cross-platform solution, however a Windows only one would be acceptable. ...

Why is lock(this) {...} bad?

The MSDN documentation says that public class SomeObject { public void SomeOperation() { lock(this) { //Access instance variables } } } is "is a problem if the instance can be accessed publicly". I'm wondering why? Is it because the lock will be held longer than necessary? Or is there some more insidious reason...

Is it possible to implement scoped lock in C#?

Hi. A common pattern in C++ is to create a class that wraps a lock - the lock is either implicitly taken when object is created, or taken explicitly afterwards. When object goes out of scope, dtor automatically releases the lock. Is it possible to do this in C#? As far as I understand there are no guarantees on when dtor in C# will run a...

How does SQL Server locking work in this scenario?

Consider that I have a transaction: BEGIN TRANSACTION DECLARE MONEY @amount SELECT Amount AS @amount FROM Deposits WHERE UserId = 123 UPDATE Deposits SET Amount = @amount + 100.0 WHERE UserId = 123 COMMIT And it gets executed on 2 threads, in the order: thread 1 - select thread 2 - select thread 1 - update thread 2 - update ...

How do I copy a file or folder that is locked under windows programmatically?

What are the API calls to copy a file that is currently locked. I'm hoping to be able to use .Net, but Win32 calls would be fine as well. Please feel free to chime in about the same functionality on Unix, or any other OS. ...

mysql insert race condition

How do you stop race conditions in MySQL? the problem at hand is caused by a simple algorithm: select a row from table if it doesn't exist, insert it and then either you get a duplicate row, or if you prevent it via unique/primary keys, an error. Now normally I'd think transactions help here, but because the row doesn't exist, the t...

Why the Global Interpreter Lock?

What is exactly the function of Python's Global Interpreter Lock? Do other languages that are compiled to bytecode employ a similar mechanism? ...

Run a script when either locking or unlocking Windows XP

I have a Windows XP machine and a Linux machine running Ubuntu. I share the keyboard/mouse from the Windows machine via Synergy. What I would like to do is lock/unlock the Linux machine whenever I lock/unlock the Windows machine. So I'd like to be able to run a script of some description when Windows either locks or unlocks the screen. ...

Is there a slim reader/writer lock for .NET 2.0?

I've looked at the ReaderWriterLock in .NET 2.0 and the ReaderWriterLockSlim in .NET 3.5, and the slim version doesn't use kernel objects for the locking. For my context, which can potentially generate a large (but not huge) amount of objects, this sounds better. But the code I write needs to be used in both .NET 2.0 and 3.5 during a tr...

Transaction level, nolock/readpast and concurrency

We have a system that is concurrently inserted a large amount of data from multiple stations while also exposing a data querying interface. The schema looks something like this (sorry about the poor formatting): [SyncTable] SyncID StationID MeasuringTime [DataTypeTable] TypeID TypeName [DataTable] SyncID TypeID DataC...

SQLite non-exclusive RESERVED lock?

I've been looking into improving SQLite performance for my site, especially with regard to transactions. In essence what I'm looking for is a way to defer database writes in a process so that they can all be done at once. However, while I'm accumulating update queries, I would like other processes to be able to both read from and write t...

When should I use Scope Locking (Application, Server, etc...) vs named locking in ColdFusion?

When is it appropriate to use <cflock scope="application"> or it's ilk as opposed to <cflock name="foo">? Specifically, I'm interested in using CFLock to protect shared objects in the application, session, or server scopes, but I'm also interested in finding out about different uses of locking in ColdFusion. ...