locking

Is this Python producer-consumer lockless approach thread-safe?

I recently wrote a program that used a simple producer/consumer pattern. It initially had a bug related to improper use of threading.Lock that I eventually fixed. But it made me think whether it's possible to implement producer/consumer pattern in a lockless manner. Requirements in my case were simple: One producer thread. One consume...

Directory.GetFiles() gives weird return values

This problem occurs when I try to hide a file in my directory with a tool named File Lock. This is not a regular hide as I can not see it in windows explorer. Code: string[] textFiles = Directory.GetFiles(@"c:\mydir") //0 files returned string[] textFiles = Directory.GetFiles(@"c:\mydir", "*.txt") //1 file returned: "c:\mydir\." File....

Do I need a lock when only a single thread writes to a shared variable?

I have 2 threads and a shared float global. One thread only writes to the variable while the other only reads from it, do I need to lock access to this variable? In other words: volatile float x; void reader_thread() { while (1) { // Grab mutex here? float local_x = x; // Release mutex? do_stuff_wi...

Spring JDBCTemplate Table Locking with MySQL

Hi! I just migrating one of our applications from pure JDBC to Spring's JDBCTemplate. I was wondering how to create a write lock for a table. Do i just execute a "LOCK TABLE foo" Query or is there a generalisized way for doing this in JDBCTemplate? Thanks! ...

SQL Server lock escalation issue

Hello everyone, I am reading SQL Server lock escalation from MSDN Page about SQL Server lock escalation My question is, seems the major reason why there is lock escalation is to reduce overhead to maintain more locks (e.g. when more row locks are acquired for a table, then row level lock is escalated to table level). My question is, to...

Troubleshooting consistent "SQLException: Lock wait timeout exceeded"

I have an application running Quartz 1.6.1 w/persistent job store, with MySQL 5.1 as the DB. This application used to boot up okay in Tomcat6. At some point, it began throwing the following exception upon EVERY boot: - MisfireHandler: Error handling misfires: Failure obtaining db row lock: Lock wait timeout exceeded; try restarting tran...

Why is it better to lock(objLock) than lock(this)

Possible Duplicates: Why is lock(this) {...} bad? In C# it is common to use lock(objLock) where objLock is an object created simply for the purpose of locking. Why is this preferable to lock(this)? What are the negative implications of lock(this) other than taking a lock out on the class itself? ...

Are we asking too much of transactional memory?

I've been reading up a lot about transactional memory lately. There is a bit of hype around TM, so a lot of people are enthusiastic about it, and it does provide solutions for painful problems with locking, but you regularly also see complaints: You can't do I/O You have to write your atomic sections so they can run several times (be c...

Locking removable drive?

Friends, How to lock/unlock(software based) removable disk/drives in VB6? I need to know any specific win32 routines are there for this purpose? ...

Difference Between Monitor & Lock?

What's the difference between a monitor and a lock? If a lock is simply an implementation of mutual exclusion, then is a monitor simply a way of making use of the waiting time inbetween method executions? A good explanation would be really helpful thanks.... regards ...

How to see SQL 2008 Locks and Blocked Tables

Hi. During the ASP.NET execution of my app, it seems SQL 2008 Express holds some lock, and I get Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding Maybe some of my query is not optimized. Visual Studio crashes with: Microsoft Visual Studio may be unstable now. ...

database locking problems with django

I have a webpage which interacts with several external APIs and in order to speed things up (the speed increase is almost linear because the majority of the time is spent waiting for http responses, etc), the code is threaded so that it pulls the content from several APIs at once. The problem is, I am running into database locking presu...

Any way to select without causing locking in MySQL?

Query: SELECT COUNT(online.account_id) cnt from online; But online table is also modified by an event, so frequently I can see lock by running show processlist. Is there any grammar in MySQL that can make select statement not causing locks? And I've forgotten to mention above that it's on a MySQL slave database. After I added into ...

Demonstrate C# Convoy Lock

A Couple of years back due to a improperly implemented "Try Catch Finally" block the development team struggled with a runtime freeze which was later discovered as a case of Convoy Lock Issue. I am looking for a simple C# code to demonstrate a Convoy Locking to my fellow team mates. Any help for a code sample would be great. ...

when will select statement without for update causing lock?

I'm using MySQL, I sometimes saw a select statement whose status is 'locked' by running 'show processlist' but after testing it on local,I can't reproduce the 'locked' status again. ...

Assigning data-entry tasks to multiple concurrent web-app users

I'm trying to think of an efficient way to allow a group of people to work through a queue of data entry tasks. Previously we've just had one person doing this so it hasn't been an issue. The back-end is an RDBMS and the front-end is a web-application. Currently we do something like this: To assign a record for editing: SELECT * FRO...

When are shared read locks released?

When SQL Server Books online says that "Shared (S) locks on a resource are released as soon as the read operation completes, unless the transaction isolation level is set to repeatable read or higher, or a locking hint is used to retain the shared (S) locks for the duration of the transaction." Assuming we're talking about a row-level ...

What's wrong with this fix for double checked locking?

So I've seen a lot of articles now claiming that on C++ double checked locking, commonly used to prevent multiple threads from trying to initialize a lazily created singleton, is broken. Normal double checked locking code reads like this: class singleton { private: singleton(); // private constructor so users must call instance() ...

Implementing a global lock in Java

Hi, I have a relatively simple (perhaps stupid) question regarding synchronisation in Java. I have synchronisation blocks that acquire locks on various objects throughout my code. In some scenarios, I want to acquire a global lock that subsumes every other synchronisation statement in my code. Is there a fancy way to do this in Java w...

How many kinds of lock are there which can be used to design?

In a program, I can design lock to threads,lock to object or files. Are there difference between these locks? If yes, how many kinds of lock are there which can be used to design? Are there some tutorials to design locks in object-oriented programming? ...