locking

Queueing with cflock on Coldfusion 9

We've been dealing with a problem with our event gateways since we upgraded from ColdFusion 8 Enterprise to ColdFusion 9 Enterprise. We have an event gateway setup to establish a connection to a third party. They went us updates at least every 10 seconds and sometimes many times a second. We have a Java class configured as the Event ...

PDO, mysql, transactions and table locking

For fun I am replacing the mysqli extension in my app with PDO. Once in awhile I need to use transactions + table locking. In these situations, according to the mysql manual, the syntax needs to be a bit different. Instead of calling START TRANSACTION, you do it like so... SET autocommit=0; LOCK TABLES t1 WRITE, t2 READ, ...; ... do ...

locking mechanism that provides information about the state in .NET 3.5

I'm trying to find a way to provide exclusive access to a resource, while at the same time providing information about the state of the lock (_isWorking) for other classes to read. Here's what I have come up with so far : private int _isWorking = 0; public bool IsWorking { get { return Interlocked.CompareExchange(r...

what the difference between a lock and a latch in the context of concurrent access to a database

I am trying to understand a paper on concurrent B-tree, in which the author mentioned latch vs lock, and how latches do not need a "Lock Manager". I have been trying to figure out what are differences between those two for two days. Google resulting in: "locks assure logical consistency of data. They are implemented via a lock table, ...

Automatic locking of DirectX buffers

I'm currently dealing with some old DirectX code that looks (quite often at very different places) something like this: LPDIRECT3DVERTEXBUFFER9 buffer; //create the vertex buffer correctly here ... buffer->Lock(...); //loop through the buffer to check something for(...) { if(checkPositive) return true; //some other code still in...

Conflict on Locking two methods so that only 1 Thread can use the lock

Hi, I have a problem regarding multithreading and inserting an item to an Dictionary. The following situation is what I am encoutering when insertingen subjects with duplicate id's: private static readonly Timer bufferChecker; private static readonly List<SubjectStartRulePair> inBuffer; private static readonly IDictionary<Gu...

Lock Mysql table for write but allow read

Is there a way to lock a Mysql table only for write, so that another script can still make a SELECT query? I'm using this code to write to a table (executes almost every second): mysql_query("LOCK TABLES table WRITE;"); mysql_query("insert into... mysql_query("UNLOCK TABLES;"); and this to select (this script just freezes, probably b...

Why does lock(this) thread.sleep not work with ASP.NET threading ?

Hi I have a password page and when someone enters an incorrect password I want to simply foil a brute force attack by having bool isGoodPassword = (password == expected_password); lock (this) { if (!isGoodPassword) Thread.Sleep(2000); } I would expect that this would allow all correct passwords without stalling, but ...

What is the best approach to thread-safe multiple parallel readers threads and occasional writer thread on an ArrayList object to a C# application?

Consider the scenario below: The application is multi-threaded and it has one static ArrayList used globally. The application has one thread that reconstruct the ArrayList entirely from data read from database from time to time. The application has N threads reading from this global ArrayList in parallel. What is the best approach to...

Order of locks in query (postgresql)

Database has table X and tables An, Bn, Cn, Dn that inherits from X. Process 1 queries periodically data from X. Process 2 updates data in child tables. For example, to update tables An and Bn it creates new tables Am and Bm, loads data into them, locks in access exclusive An, Bn, drops An and Bn and alters Am and Bm to inherit X. The...

Lock vs. ToArray for thread safe foreach access of List collection

I've got a List collection and I want to iterate over it in a multi threaded app. I need to protect it every time I iterate it since it could be changed and I don't want "collection was modified" exceptions when I do a foreach. What is the correct way to do this? Use lock every time I access or loop. I'm rather terrified of deadlock...

Message-based multithreading or Thread Pool for a short and uncommon action?

I'm currently using Retlang for message-based multithreading in .NET, which is a great library. I've got no explicit locks anymore, every thread is doing its own business, managing its part of the application and communicating with other threads via messages. I now have to implement a feature of my application that could also have its o...

How to use Multithreading, locks, Socket Programming.

For last 48 hours, I have been trying to understand Multithreading and Socket Programming. I tried to implement socket programming and had success when not using multithreading. I am new to both of the topics and have raised 2-3 question on stack itself needing help on the same. After googling a lot I found an article that explains So...

How to lock a setter property for a thread.

I am running four threads that gets and sets the same property. When i uses breakpoint then it gives me result as expected but when i runs it directly it gives me last updated result. Here is my code int Port { get; set; } Thread[] tMain= new Thread[4]; public void btnListen_Click(object sender, EventArgs e) { for...

Trace a deadlock in Ruby

I use BrB to share a datasource for various worker processes in Ruby 1.9 that I fork with Process#fork like the following: Thread.abort_on_exception = true fork do puts "Initializing data source process... (PID: #{Process.pid})" data = DataSource.new(files) BrB::Service.start_service(:object => data, :verbose => false, :host => ...

Release locks in Subversion recursively

Hello all I am having a problem with version control in subversion. I checked out a working copy from respository and got locks on all of its files. Then, without releasing the locks I have deleted the folder from disk. I can't delete the folder from repository, since its got a lock If the I and try to release the locks recursively, i...

Close and dispose of resources before displaying error messages?

Is it good practice to close and dispose of resources before displaying error messages? If you are catching errors and you display an error message in the same scope as resources such as database and file objects, then shouldn't these resources be closed and disposed of before the error message is displayed? If you are waiting for th...

How to work around ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.

I want to lock one record in a table. The record is specified as "the next that has ID greater than..." CREATE TABLE test (id number); SELECT id FROM (SELECT id FROM test WHERE id > 10 ORDER BY id) WHERE ROWNUM = 1 FOR UPDATE; This seems intuitive and easy. But it is not. Any ideas? P.S. I do need the existing qu...

LockFileEx read/write upgrade/downgrade

I have the need to open a file, read-lock it, then attempt to get a write lock but keep the read lock if it fails. This works great in POSIX using fcntl locking. In Windows I can use LockFileEx to get file locks. I can get both read and write locks (shared and exclusive). However, it seems that in Windows I must take the exclusive wri...

Android detect phone lock event

I want to be able to detect the phone lock event. When my app is running, if I press the red button (call end button/power button), the phone gets locked and the screen goes blank. I want to be able to detect this event, is it possible? Thanks Chris ...