locking

FileStream locking a file for reading and writing

不想你离开。 提交于 2019-12-01 05:15:39
I have the following code block which is giving me a headache. Logically it should work as I am using the filestream providing the lock within the using statement. When it gets to the line that creates the StreamWriter, it fails saying "the file is not writable". Now my program is a multithreaded application. Any thread could be trying to write to this file. I need the program to lock the file, read the contents, check the contents, then write back any changes. During that process, no other thread should be able to access that file. using (var fs = File.Open(fileLoc, FileMode.Open, FileAccess

Add new column without table lock?

走远了吗. 提交于 2019-12-01 04:55:58
问题 In my project having 23 million records and around 6 fields has been indexed of that table. Earlier I tested to add delta column for Thinking Sphinx search but it turns in holding the whole database lock for an hour. Afterwards when the file is added and I try to rebuild indexes this is the query that holds the database lock for around 4 hours: "update user_messages set delta = false where delta = true" Well for making the server up I created a new database from db dump and promote it as

Swing Application stuck following Apple Java update 1.6.0_51

℡╲_俬逩灬. 提交于 2019-12-01 04:38:37
问题 We have a Java Swing client application. It's installed as a Java Web Start applet and as a install4j installer. Since Apple released the latest Java 6 upgrade our application gets stuck immediately after Login Dialog is displayed on both Installer and Web Start versions. We disabled the dialog, the application still got stuck immediately after the start. We also tried to use different Look&Feels, as there are some reports that this fixes the issue, it didn't help. We currently suspect that

Do semaphores prevent instruction reordering?

烈酒焚心 提交于 2019-12-01 04:09:39
问题 I was looking for an awaitable equivalent of lock statements in C#. Some people suggest using a binary SemaphoreSlim in the following way: await semaphore.WaitAsync().ConfigureAwait(false); try { //inner instructions } finally { semaphore.Release(); } I know it has some issues (e.g. it's not reentrant), but my biggest concern is with the instruction reeordering. In plain old lock statements we have a guarantee that no inner instruction from the lock will be moved outside (before or after) the

Multithreading: do I need protect my variable in read-only method?

六眼飞鱼酱① 提交于 2019-12-01 04:00:43
I have few questions about using lock to protect my shared data structure. I am using C/C++/ObjC/Objc++ For example I have a counter class that used in multi-thread environment class MyCounter { private: int counter; std::mutex m; public: int getCount() const { return counter; } void increase() { std::lock_guard<std::mutex> lk(m); counter++; } }; Do I need to use std::lock_guard<std::mutex> lk(m); in getCount() method to make it thread-safe? What happen if there is only two threads: a reader thread and a writer thread then do I have to protect it at all? Because there is only one thread is

What is a stored procedure with a padlock icon in SQL Server 2005?

99封情书 提交于 2019-12-01 03:32:08
I see some stored procedures in one database I'm managing that have the regular stored procedure icon, but with a little padlock next to them. The differences I see is that I can't "modify" them, and if I try to script them, it says: Text is Encrypted. Is this because these are CLR stored procedures? Are they "regular" procedures, but encrypted/protected somehow? Is there any way to get to the code of those (either the T-SQL or the IL)? Aaron Alton The padlock means that the stored procedure has been encrypted using the WITH ENCRYPTION hint (see CREATE PROC in BOL for more information). It

How perform SQLite query with a data reader without locking database?

笑着哭i 提交于 2019-12-01 03:31:30
I am using System.Data.Sqlite to access SQLite database in C#. I have a query which must read through rows in a table. While iterating through the rows and while the reader is open, certain SQL updates must be performed. I am running into a "database is locked" exception. The SQLite documentation states: When a process wants to read from a database file, it followed the following sequence of steps: Open the database file and obtain a SHARED lock. The documentation further states about "SHARED" locking: The database may be read but not written. Any number of processes can hold SHARED locks at

Thread safety object - static or not?

十年热恋 提交于 2019-12-01 03:26:11
I was recently in an interview and the tech guy asked me about how to make an application thread-safe. Well, after explaining the lock() correctly, he said it is not a good idea to have the object as static. private static readonly object _syncLock = new object(); He claimed the reason is that static makes that object slower for threads to lock than if it was non static. Is this true? EDIT: Nonetheless I am still not sure. What is the difference between these three approaches? private static readonly object _syncLock = new object(); public static readonly object _syncLock = new object();

Java: How to check if a lock can be acquired? [duplicate]

不问归期 提交于 2019-12-01 03:21:55
This question already has an answer here: How do determine if an object is locked (synchronized) so not to block in Java? 7 answers If I want to ensure exclusive access to an object in Java, I can write something like this: ... Zoo zoo = findZoo(); synchronized(zoo) { zoo.feedAllTheAnimals(); ... } Is there a way to check if an object is currently locked? I don't want my thread to wait if another thread is accessing zoo . If zoo is not locked, I want my thread to acquire the lock and execute the synchronized block; if not, I want it to skip it. How can I do this? You can't do it using the low

FileStream locking a file for reading and writing

坚强是说给别人听的谎言 提交于 2019-12-01 03:00:13
问题 I have the following code block which is giving me a headache. Logically it should work as I am using the filestream providing the lock within the using statement. When it gets to the line that creates the StreamWriter, it fails saying "the file is not writable". Now my program is a multithreaded application. Any thread could be trying to write to this file. I need the program to lock the file, read the contents, check the contents, then write back any changes. During that process, no other