Questions tagged [locking]

Locking allows different types of resources to be used exclusively by one process at a time.

For more information see Locks in Java

8782 questions
55
votes
5 answers

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

Our website has a configuration page such as "config.aspx", when the page initializing will load some information from a configuration file. To cache the loaded information we provided a factory class and we call a public method of the factory to…
Pag Sun
  • 845
  • 1
  • 8
  • 11
54
votes
17 answers

LINK : fatal error LNK1104: cannot open file 'D:\...\MyProj.exe'

Using Visual Studio 2010, when I build + run my application in short intervals I often get the following error. If I just wait a minute or two and try again it works fine. Unlocker claims no handle is locking the executable file. How can I discover…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
54
votes
8 answers

How to improve INSERT INTO ... SELECT locking behavior

In our production database, we ran the following pseudo-code SQL batch query running every hour: INSERT INTO TemporaryTable (SELECT FROM HighlyContentiousTableInInnoDb WHERE allKindsOfComplexConditions are true) Now this query itself does…
Artem
  • 6,420
  • 6
  • 26
  • 26
53
votes
10 answers

How can I release locks in Subversion recursively?

I am having a problem with version control in Subversion. I checked out a working copy from respository and got locks on all of its files. Then, without releasing the locks I have deleted the folder from disk. I can't delete the folder from…
vikmalhotra
  • 9,981
  • 20
  • 97
  • 137
53
votes
5 answers

ReaderWriterLockSlim and async\await

I have some problems with ReaderWriterLockSlim. I cannot understand how it's magic working. My code: private async Task LoadIndex() { if (!File.Exists(FileName + ".index.txt")) { return; } …
l0nley
  • 611
  • 1
  • 5
  • 9
53
votes
7 answers

What is the best way to open a file for exclusive access in Python?

What is the most elegant way to solve this: open a file for reading, but only if it is not already opened for writing open a file for writing, but only if it is not already opened for reading or writing The built-in functions work like this >>>…
mar10
  • 14,320
  • 5
  • 39
  • 64
51
votes
1 answer

Controlling duration of PostgreSQL lock waits

I have a table called deposits When a deposit is made, the table is locked, so the query looks something like: SELECT * FROM deposits WHERE id=123 FOR UPDATE I assume FOR UPDATE is locking the table so that we can manipulate it without another…
ddoor
  • 5,819
  • 9
  • 34
  • 41
51
votes
2 answers

Why is it a bad practice to lock the object we are going to change?

Why is it a bad practice to use lock as in the following code, I'm assuming this is a bad practice based on the answers in this SO question here private void DoSomethingUseLess() { List otherProductList = new List(); …
Vamsi
  • 4,237
  • 7
  • 49
  • 74
50
votes
4 answers

If a synchronized method calls another non-synchronized method, is there a lock on the non-synchronized method

In Java, if a synchronized method contains a call to a non-synchronized, can another method still access the non-synchronized method at the same time? Basically what I'm asking is everything in the synchronized method have a lock on it (including…
dido
  • 3,347
  • 11
  • 34
  • 42
50
votes
4 answers

Is it ok to read a shared boolean flag without locking it when another thread may set it (at most once)?

I would like my thread to shut down more gracefully so I am trying to implement a simple signalling mechanism. I don't think I want a fully event-driven thread so I have a worker with a method to graceully stop it using a critical section Monitor…
John
  • 6,433
  • 7
  • 47
  • 82
50
votes
4 answers

Preventing a class from direct instantiation in Python

I have a super class with a method that calls other methods that are only defined in its sub classes. That's why, when I create an instance of my super class and call its method, it cannot find the method and raises an error. Here is an…
mohi666
  • 6,842
  • 9
  • 45
  • 51
50
votes
14 answers

Select unlocked row in Postgresql

Is there a way to select rows in Postgresql that aren't locked? I have a multi-threaded app that will do: Select... order by id desc limit 1 for update on a table. If multiple threads run this query, they both try to pull back the same row. One…
alanc10n
  • 4,897
  • 7
  • 36
  • 41
50
votes
4 answers

How to use/create unique_lock in c++?

Please, can anybody explain how to use and create an unique_lock in c++? It should be used both to get mutual exclusion to any procedure of the monitor and to be able to perform wait() on the condition variable...I'm not understanding from the…
SagittariusA
  • 5,289
  • 15
  • 73
  • 127
50
votes
2 answers

Java thread dump: Difference between "waiting to lock" and "parking to wait for"?

In a Java thread dump, you can see locks mentioned within stack traces. There seems to be three kinds of information: 1: - locked <0x00002aab329f7fa0> (a java.io.BufferedInputStream) 2: - waiting to lock <0x00002aaaf4ff6fa0> (a…
Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
49
votes
5 answers

fcntl, lockf, which is better to use for file locking?

Looking for information regarding the advantages and disadvantages of both fcntl and lockf for file locking. For example which is better to use for portability? I am currently coding a linux daemon and wondering which is better suited to use for…
cweston
  • 11,297
  • 19
  • 82
  • 107