locking

I wonder is there a better way to implement this "simple lock"

Is there a better way to do implement a simple lock like below? I only want to to the "DOSOMETHING" if it's not already being run. Should I be using reall locks here? if I use lock will that cause everything to queue up and wait for the lock to release? (that's not what I want!) Thanks bool running = false; void DataDisplayVi...

What's the least invasive way to read a locked file in C# (perhaps in unsafe mode)?

I need to read a Windows file that may be locked, but I don't want to create any kind lock that will prevent other processes from writing to the file. In addition, even if the file is locked for exclusive use, I'd like to see what's inside. Although this isn't my exact use case, consider how to read a SQL/Exchange log or database file ...

Question on using Monitor.TryEnter and locking object

Consider the following function that implements non-blocking access to only the one thread. public bool TryCancelGroup() { if (Monitor.TryEnter(_locked)) { if (_locked == false) { _locked = true; try { // do something } catch (Exception ...

C# static field locking

Do I need locking for _userByNameQuery static field Yes/No and way? public class SomeClass { static Func<Entities, string, IQueryable<User>> _userByNameQuery = CompiledQuery.Compile<Entities, string, IQueryable<User>> ((context, userName) => context.Users.Where(u => u.UserName.ToUpper() == userN...

Records write locked on a RepeatableRead

I have a SQL Server query (using the LLBL ORM, if that is important to the question) that is doing a large fetch on a set of related tables. This query is being performed in a transaction with the Isolation Level of Repeatable Read, and is being filtered by two 'state' columns in the main table of the query. Will the records being 'wri...

FileInfo lock files!

Hi all. Imagine a winform app, who copy updated assemblies from a source folder A to a destination folder B. I use simple DirectoryInfo.GetFiles methods to fill a listview, comparing version of assembly in folder A and B; if some assemblies are newer, I start my update method. In this method, before copying, I try if all file in B folde...

Help with understanding jstack output

I have a desktop Java/Swing application which is deployed via Java Webstart (clients are using Java 6u20 on XP). I have received intermittent reports from users of the application hanging. I managed to log on to such a system during a hang found that the UI was not being drawn (as though EDT was blocked). I used jstack to list the thre...

Multiple isolation levels needed for a TransactionScope?

I am running into situations in my application where I need to use table lock hints or set the transaction isolation level to something other than the default Read Committed, in order to resolve deadlock issues. I am using a service oriented architecture, with each service call operating as an atomic operation, and Linq To Sql is servin...

How to solve the "Double-Checked Locking is Broken" Declaration in Java?

I want to implement lazy initialization for multithreading in Java. I have some code of the sort: class Foo { private Helper helper = null; public Helper getHelper() { if (helper == null) { Helper h; synchronized(this) { h = helper; if (h == null) ...

Android: Illegal View State Exception on Keyguard unlock

I have an activity, on which when I press the Keyguard lock button, the onDestroy() function is called. At then when I disable the keyguard lock, that activity is shown no more as I get a RuntimeException in Illegal View State. How can I prevent from onDestroy() to be called? Please help. ...

What needs thread-safe code here?

Lets say we have an object that can be accessed by multiple threads and a global singleton handing out the object's reference, also accessible by multiple threads. class Book { private string title; public Book(string title) { this.title = title; } public string Title { get { return title; } } } class Bookstore...

Double-checked locking for growable array of binomial coefficients

I'm trying to use double-checked locking to maintain an array of binomial coefficients, but I read recently that double-checked locking doesn't work. Efficiency is extremely important so using volatile isn't an option unless it's only inside the conditional statements. I can't see a way to use a static class with a singleton object (th...

Debugger unlocks lock? VS 2008

Hello =) I have implemented a singleton that works well... (implemented like this example: public sealed class Singleton { static Singleton instance=null; static readonly object padlock = new object(); Singleton() { //breakpoint } public static Singleton Instance { get { ...

Release a lock temporarily if it is held, in python

I have a bunch of different methods that are not supposed to run concurrently, so I use a single lock to synchronize them. Looks something like this: selected_method = choose_method() with lock: selected_method() In some of these methods, I sometimes call a helper function that does some slow network IO. (Let's call that one netw...

Should I protect operations on primitive types with mutexes for being thread-safe in C++?

What is the best approach to achieve thread-safety for rather simple operations? Consider a pair of functions: void setVal(int val) { this->_val = val; } int getVal() { return this->_val; } Since even assignments of primitive types aren't guaranteed to be atomic, should I modify every getter and setter in the program in th...

Swapping a running jar at runtime

I am building an update system in which I need to be able to replace a referenced jar of a running application jar at runtime. I am finding I am running into file locking issues on Windows when trying to perform file utility functions on the jar such as 'setLastModified'. After some googling I found this snippet... What I found in m...

Multithreading on Static Methods/Classes

Do We really need Locking for Static methods(Static Class) when the methods are heavily used by threads? Is it required when Static methods are using resources like SQL Queries/StoredProcedures ? Thanks Pankaj ...

Oracle Transactions doesn't work as expected in some client machines in a .net windows application

Hi. I have an windows application in VB.NET (2.0) and Oracle Database, the connections are handled by System.Data.OracleClient. My oracle client is 10g. In the server side, the AutoCommit is off. The application uses transtactions (isolationLevel: ReadCommitted) for certain operations. The problem is that in some machines (and only in...

Return unlocked rows in a "select top n" query

I need to have a MsSql database table and another 8 (identical) processes accessing the same table in parallel - making a select top n, processing those n rows, and updating a column of those rows. The problem is that I need to select and process each row just once. This means that if one process got to the database and selected the top ...

unable to build ant with Clearcase on VMware

So here is the problem. I have a local snapshot in my local windows system and i run my ant script and it builds. I have build system which is also winxp but its a vmware built inside ubuntu. i have also a snapshot there too in winxp , and my script runs against this. But clearcase doesnt allow to write anything on this folder and buil...