locking

How do I make this transaction safe in a concurrent environment? (SQL Server 2005)

Suppose I have these two tables: Invoice ------- iInvoiceID int PK not null dtCompleted datetime null InvoiceItem ----------- iInvoiceItemID int PK not null iInvoiceID int FK (Invoice.iInvoiceID) not null dtCompleted datetime null Each InvoiceItem might be fulfilled by a different process (executable) that runs on a different machine...

Why doesn't locking a cell in a protected worksheet in Excel prevent selection?

I'm working on a protected Excel spreadsheet and ran into a problem with cells that I've programmatically locked that are still selectable. I can't click on them directly to select them, but if I select the cell to the lower right of a locked cell and then shift-click the one to the upper left, all 9 cells (including the 'locked' one) a...

Can I lock(something) on one line in C#?

Will the _otherThing field below be protected by the locks? class ThreadSafeThing { private readonly object _sync = new object(); private SomeOtherThing _otherThing; public SomeOtherThing OtherThing { get { lock(_sync) return _otherThing; } } public void UpdateOtherThing(SomeOtherThing otherThing) { lock(_...

C# Threading/Lock confusion

I have the following code: var items = new List<string> {"1", "2", "3"}; // 200 items foreach(var item in items) { ThreadPool.QueueUserWorkItem((DoWork), item); } private void DoWork(object obj) { lock(this) { using(var sw = File.AppendText(@"C:\somepath.txt") { sw.WriteLine(obj); } } } Because of the thread...

Viewing a list of locks in Coldfusion

Hi there, Is there anyway to see a list of the current locks in Coldfusion (particularly locks on files or directories). Through a non documented call is fine as this is more for debugging some errors we're getting on our server. Thanks, Tom ...

C# threading - Lock Object

Hi, I am trying to lock a "boxed" object in a c# app, is this not possible? class t { System.Object t_x = new object(); public t(int p) { t_x = p; } public void w() { lock (t_x) { for (int i = 0; i < 4; i++) { ...

C# Threading issue with AutoResetEvent

How to properly synchronize this? At the moment it is possible thatSetData is called after e.WaitOne() has completed so d could be already set to another value. I tried to insert locks but it resulted into a deadlock. AutoResetEvent e = new AutoResetEvent(false); public SetData(MyData d) { this.d=d; e.Set(); // notify that ne...

Under which circumstances does the System process (PID 4) retain an open file handle?

My application running on a Windows server makes use of a Jet/Access database. For some reasons around every two weeks that database file gets locked by the System process (PID 4, seems to be fixed) After some googling I found some other users having their files locked by that special process, but different files (of course). What's t...

accept() with sockets shared between multiple processes (based on Apache preforking)

I'm working on some Python code modeled on Apache's MPM prefork server. I am more an applications programmer than a network programmer and it's been 10 years since I read Stevens, so I'm trying to get up to speed in understanding the code. I found a short description of how Apache's prefork code works, by Sander Temme. The parent pr...

detach database/take offline fails

Hi, I'm currently in the process of detaching a development database on the production server. Since this is a production server I don't want to restart the sql service. That is the worst case scenario. Obviously I tried detaching it through SSMS. Told me there was an active connection and I disconnected it. When detaching the second t...

C# locking and general threading design question

I have a threaded console application that is working fine, but it's architecture needs to be improved, and I'd like some feedback. Currently, the program loads up a list of data, and segments that data into partitions (one chunk for each thread). The program then initializes a new thread using the ThreadPool, and passes it ONE segment...

SharePoint: Timerjobs Lock Type

Hi I am trying to create a timer job in WSS 3.0. My timer job would create the object of SPsite then SPWeb and then SPDocumentLibrary (or possibly picture library)using their GUIDs stored in any xml or database.After that it would take the back up of documents in the document library in some third party application and then delete thos...

What is the Re-entrant lock and concept in general?

I am always get confused . Would someone example what Reentrant means in different contexts? And why would you want to use reentrant vs. non-reentrant. Say pthread (posix) locking primitives, are the re-entrant or not? What pitfalls should be avoided when using them Is mutex re-entrant? Thanks ...

Mutually exclusive flags on file_put_contents?

On the file_put_contents() documentation, it says the following: FILE_APPEND: Mutually exclusive with LOCK_EX since appends are atomic and thus there is no reason to lock. LOCK_EX: Mutually exclusive with FILE_APPEND. Yet, a couple of lines bellow I see the following code: <?php $file = 'people.txt'; // The new person t...

Throw a NullReferenceException while calling the set_item method of a Dictionary object in a multi-threding scenario

Our website has a configuration page such as "config.aspx", when the page initializing will load some infomations from a configuration file. To cache the loaded informations we provided a factory class and we call a public method of the factory to get the configuration instance when the page loaded. But sometimes when the Applciation Poo...

MySQL from the command line - can I practically use LOCKs?

I'm doing a bash script that interacts with a MySQL datatabase using the mysql command line programme. I want to use table locks in my SQL. Can I do this? mysql -e "LOCK TABLES mytable" # do some bash stuff mysql -u "UNLOCK TABLES" The reason I ask, is because table locks are only kept for the session, so wouldn't the lock be released...

Safe to get Count value from generic collection without locking the collection?

I have two threads, a producer thread that places objects into a generic List collection and a consumer thread that pulls those objects out of the same generic List. I've got the reads and writes to the collection properly synchronized using the lock keyword, and everything is working fine. What I want to know is if it is ok to access ...

Multi-process synchronization - better choice than semaphores?

I've got a queue resource that is shared across multiple producers and multiple consumers. All are independent processes; no one process "owns" the queue. By nature of the implementation access to the queue must be controlled and only one process must be allowed to push or pop at any given moment. I figured using a POSIX named semapho...

Sychronizing on an interned String

usecase example I have a servlet that is receiving login requests. If a login is currently in process OR the user is already logged in, the servlet should abort and inform the caller. current design Taking inspiration from database sharding, I plan to use the first character of each userid as a synchronization key. void login( Stri...

How to change locking strategy in SQL Server?

I've read articles like these: http://www.codinghorror.com/blog/archives/001166.html http://www.databasejournal.com/features/mssql/article.php/3566746/Controlling-Transactions-and-Locks-Part-5-SQL-2005-Snapshots.htm And from what I understand, SQL Server has a very pessimistic locking strategy. And to improve performance, I should chang...