locking

How to implement locking across a server farm?

Are there well-known best practices for synchronizing tasks across a server farm? For example if I have a forum based website running on a server farm, and there are two moderators trying to do some action which requires writing to multiple tables in the database, and the requests of those moderators are being handled by different server...

Reading interlocked variables

Assume: A. C++ under WIN32. B. A properly aligned volatile integer incremented and decremented using InterlockedIncrement() and InterlockedDecrement(). __declspec (align(8)) volatile LONG _ServerState = 0; If I want to simply read _ServerState, do I need to read the variable via an InterlockedXXX function? For instance, I have seen...

How to lock on an integer in C#?

Is there any way to lock on an integer in C#, integers can not be used with lock because they are boxed (and lock only locks on references). The scenario is as follows, I have that forum based website which support moderation, I want to make sure that no more than one moderator can moderate a post at a time, for this I want to use the I...

Primitive synchronization primitives -- safe?

On constrained devices, I often find myself "faking" locks between 2 threads with 2 bools. Each is only read by one thread, and only written by the other. Here's what I mean: bool quitted = false, paused = false; bool should_quit = false, should_pause = false; void downloader_thread() { quitted = false; while(!should_quit) { ...

Do i need a lock on a list? C#

I filled several list<> with default values, stuck them into a struct then pass the struct into several threads. Each thread has a different range so thread 1 would access list[0 to 199] thread 2 would access [200 - 400] etc. Would i need a lock? and when do i need it? i can access the list with my multiple threads w/o using a lock. But...

How to Site-Lock a Flash Application?

I have a flash application that I am going to put up on my website shortly. I want to be able to "lock it" to the site to prevent: Hosting the .SWF on another site (after an illicit download), and Preventing the .SWF from opening if included in an iFrame on another site While allowing: A whitelist of sites to be passed through/enab...

Forcing a query timeout in SQL Server

We have had an issue with a block of code that responds poorly in the face of slow databases (It craps the bed on a query timeout). We have created a patch, and are in the process of running it through regression. We can't get a timeout. I've opened a transaction from SQL Mgmt Studio and updated every row to lock them, but that doesn't ...

why does this code lock my files?

Ive narrowed down to this method but i don't understand why its locking the file. I believe you could use something like using( something) { //do stuff here } But im not sure that would A) solve the issue or B) be the correct way if it did. any ideas? [DllImport("user32.dll", CharSet = CharSet.Auto)]private static extern Int32 Syst...

ReaderWriterLockSlim Extension Method Performance

I've been playing with collections and threading and came across the nifty extension methods people have created to ease the use of ReaderWriterLockSlim by allowing the IDisposable pattern. However, I believe I have come to realize that something in the implementation is a performance killer. I realize that extension methods are not sup...

Under what circumstances will Active Record fail to enforce optimistic locking?

I watched in horror this morning as a script, running on two different machines, happily loaded, updated, and saved. I'm running ruby 1.8.6, AR 2.2.2. I started playing with some test cases and found reduced it to a minimal reproduction case: irb(main):059:0> first = Job.find :first => #<Job id: 323, lock: 8, worker_host: "second"> i...

Why does activerecord optimistic locking work only once per row?

Somehow, I always get these on Fridays. My earlier question was regarding the same problem, but I can now narrow things down a bit: I've been playing with this all day, trying to make sense of it. I have a table with a lock_version colum, specified thus: add_column :jobs, :lock_version, :integer, :default=>0 And I do something like...

Application area of lock-striping

The ConcurrentHashMap of JDK uses a lock-striping technique. It is a nice idea to minimize locking overhead. Are there any other libraries or tools that take advantage of it? For example, does database engine use it? If the technique is not so much useful in other areas, what is the limitation of it? ...

Non threadlocked Mutex

This is an offshoot of this question but with a few constraints removed. I have a system where I need to manage file locking. I need to be able to lock a file (shared read locking) in one thread and then unlock it in another. More accurately, I can't be sure what thread it will be unlocked in or even if the creating thread is still arou...

J2EE concurrency & locking

I have a MDB (Message driven bean) that receives messages with String which represent a word. Also I have a table in the database. The MDB should store in the table, the words and the number of times each word was received (counter). The problem is that to get better performance the MDB started in many instances and when the same new wo...

Inter process Reader Writer lock (or file handles and access denied)

Okay, some background first. We needed an inter-process reader/writer lock. We decided to use a file and lock the first byte using LockEx and UnlockEx. The class creates a file in the system temp folder when it is created. The file is created with readwrite access and share read|write|delete. We also specify DeleteOnClose so we don'...

What is the equivalent for LOCK_ESCALATION = TABLE in SQL Server 2005?

I have a script that was generated in SQL Server 2008, but I need to execute it against a SQL Server 2005 database. What would an equivalent statement for the following be in SQL Server 2005? ALTER TABLE dbo.Event SET (LOCK_ESCALATION = TABLE) ...

SQL Server/ADO.NET: Locking issues

I understand this is a VERY vague question, so forgive me. A company I used to work for has contacted me saying that since they've upgraded to SQL Server 2008, they've been encountering a ton of "locking" issues. I really don't know what this means. I don't even know how to see these "locking" errors in SQL Server. This was not my area...

Is a lock (wait) free doubly linked list possible?

Asking this question with C# tag, but if it is possible, it should be possible in any language. Is it possible to implement a doubly linked list using Interlocked operations to provide no-wait locking? I would want to insert, add and remove, and clear without waiting. ...

C# multi-threading code review

Is it important that I lock around the queue? public abstract class ExpiringCache<TKey,TValue> : IDisposable { protected readonly object locker = new object(); protected readonly Dictionary<TKey, TValue> cache = new Dictionary<TKey, TValue>(); private readonly Queue<KeyValuePair<TKey, long>> queue = new Qu...

sql_who2 gives -2 in the BlkBy column

We had a problem today on our dev server where a process locked one table, stopping all other queries on that table to work. When running sql_who2 the blkBy columns value was -2, but the -2 was not in the process list. When running DBCC INPUTBUFFER (-2) I got the exception Invalid SPID -2 specified. When running beta_lockinfo I see all...