locking

How to deliberately lock a MySQL row such that even SELECT will return an error?

I'm trying to use MySQL row locking to basically emulate a MuteEx on a row. Lets say that my table has 2 columns, an id and a text field, and three entries (1,a) (2,b) and (3,c). SELECT * FROM table; would return these results. I can lock a specific row the normal way. START TRANSACTION; BEGIN; SELECT * FROM table WHERE id = '2' FOR UPD...

Is this a safe version of double-checked locking?

Here's an idea I just came up with for a safe, efficient way of handling Singleton synchronization issues. It's basically double-checked locking, but with a twist that involves thread-local storage. In Java/C#/D-style pseudocode, assuming __thread denotes thread-local storage for static variables: class MySingleton { __thread stat...

Java Synchronized Block for .class

What does this java code means? Will it gain locks on all objects of 'MyClass' synchronized(MyClass.class) { //is all objects of MyClass are thread-safe now ?? } And how the above code different from this one: synchronized(this) { //is all objects of MyClass are thread-safe now ?? } ...

Locking files in linux with c/c++

I am wondering if you can : lock only a line or a single character in a file in linux and the rest of the file should remain accessible for other processes? I received a task regarding simulating transaction on a file with c/c++ under linux . Please give me an answer and if this answer is yes ,give me some links from where i could take a...

Get first unlocked row in MYSQL

When someone visits my website, he will see the page with the fewest pageviews. All pages, including a pageview counter, are stored in a MYSQL database. If a page is viewed, the pageview counter is increased by one. I now run into a Racing condition if my webserver has more than one thread: Thread 1: User A retrieves page P with pa...

Average wait time performance counter - SQL2000 vs. SQL2005

The Locks performance object on SQL Server provides three counters that I'm interested in. X = Average Wait Time (ms) Y = Lock Wait Time (ms) Z = Lock Waits/sec From their descriptions I'd have imagined that X = Y / Z. However, while this is true for SQL2005, it does not seem to be true for SQL2000. I have some code that forces a dea...

How to lock/unlock a field at runtime in C#?

Can I lock/unlock fields or objects at runtime against writing? In other words something like changing objects to read-only temporarily at runtime... For example: int x = 5; // x is 5 LockObject(x); x = 7; // no change UnlockObject(x); x = 10; // x is 10 if not can you give me some possible solutions? ...

Examining KEYLOCKs in SQL Server 2005

I've been trying to solve various deadlocks we are seeing in production. We've enabled deadlock tracing. The traces show lots of blocking on KEYLOCKs like this: 01/15/2010 08:25:07,spid15s,Unknown,keylock hobtid=72057594047758336 dbid=2 objectname=tempdb.dbo.MyTable indexname=IX_MyTable id=lock36977900 mode=X associatedObjectId=720575...

Regarding SQL Server Locking Mechanism

Dear GURUs I would like to ask couple of questions regarding SQL Server Locking mechanism If i am not using the lock hint with SQL Statement, SQL Server uses PAGELOCK hint by default. am I right??? If yes then why? may be its due to the factor of managing too many locks this is the only thing i took as drawback but please let me know ...

ie freezes using mootools request.html ajax

this is the method: var ajaxRequest = new Request.HTML({ method: 'post', url: url + "?dt=" + Date(), onFailure: function(item) { alert(item.responseText); }, onRequest: function(item) { gui.preloader('on'); }, onSuccess: function(html) { gui.preloader('off'); element.s...

Which is faster, a function call with a lock, or a virtual call?

I have a class which doesn't currently need to be thread-safe, but in future we might want to make a thread-safe version. The way I see it, I can either make it thread-safe now by putting locks around the relevant functions, or I can make them virtual now and put locks around them in overrides in a descendent class later on. That is, t...

Minimal-locking thread-safe hashtable?

Are there any available implementations of a Hashtable that provide thread safety with minimal locking in .NET? Or in another language that can be ported to .NET? We're looking for something in between using a BCL Dictionary<,> class with lock() and a distributed caching application like memcached or Velocity. The intended use is for ...

Using lock statement within a loop in C#

Lets take the sample class SomeThread where we are attempting to prevent the DoSomething methods from being called after the Running property is set to false and Dispose is called by the OtherThread class because if they are called after the Dispose method is the world would end as we know it. It feels like there is a chance for somethi...

Object vs byte[0] as lock

I commented earlier on this question ("Why java.lang.Object is not abstract?") stating that I'd heard that using a byte[0] as a lock was slightly more efficient than using an java.lang.Object. I'm sure I've read this somewhere but I can't recall where: Does anyone know if this is actually true? I suspect it's due to the instantiation o...

Is this a valid pattern for raising events in C#?

Update: For the benefit of anyone reading this, since .NET 4, the lock is unnecessary due to changes in synchronization of auto-generated events, so I just use this now: public static void Raise<T>(this EventHandler<T> handler, object sender, T e) where T : EventArgs { if (handler != null) { handlerCopy(sender, e); }...

Locking problems using SimpleReadWriteEJBLock

First of all, I am using Oracle and JBoss 4.0.4 and I'm pretty much a newbie on JBoss matters. Our distributed application uses CMP beans with SimpleReadWrite... etc locking policy, which I'm told seemed the best choice at the time. (Original developers are no longer working with us and I can't easily get feedback from them, not mention...

Is Locking really needed in my iPhone application?

I'm working on a relatively simple iPhone application that has a multi-round Timer with a number of settings such as the number of rounds and round length. We allow certain settings to be upated while the timer is running which means the timer may be reading from the same memory that the settings are writing. There are no critical sect...

C# Threading Lock error when merging images.

I'm trying to make a multithreaded program that takes a certain bitmap from a picturebox where each thread analyzes and changes part of it and then saves it back to the picturebox. I've used a lock() for the instructions that deal with the shared bitmap object and the picturebox but for some reason i still get "Object is currently in use...

Is it possible to lock lazy filed in hibernate?

I have Category class containing list of products. Like this: public class Category{ ... @0neToMany @JoinColumn("category_id") List<Product> products; public List<Product> getProducts(); ... } When I call getProducts() I want to lock returned collection so that other transaction could not modify it while current one isn't comm...

How to implement prioritized lock with only compare_and_swap?

Given only compare and swap, I know how to implement a lock. However, how do I implement a spin lock 1) multiple threads can block on it while trying to lock 2) and then the threads are un-blocked (and acquire the lock) in the order that they blocked on it? Is it even possible? If not, what other primitives do I need? If so, how do I...