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
86
votes
2 answers

Python sharing a lock between processes

I am attempting to use a partial function so that pool.map() can target a function that has more than one parameter (in this case a Lock() object). Here is example code (taken from an answer to a previous question of mine): from functools import…
DJMcCarthy12
  • 3,819
  • 8
  • 28
  • 34
85
votes
13 answers

Reader/Writer Locks in C++

I'm looking for a good reader/writer lock in C++. We have a use case of a single infrequent writer and many frequent readers and would like to optimize for this. Preferable I would like a cross-platform solution, however a Windows only one would be…
Matt Price
  • 43,887
  • 9
  • 38
  • 44
83
votes
3 answers

When and how to use Python's RLock

Reading through the Python docs I came across RLock. Can someone explain to me (with example) a scenario in which RLock would be preferred to Lock? With particular reference to: RLock's “recursion level”. How is this useful? A threads "ownership"…
Awalias
  • 2,027
  • 6
  • 31
  • 51
83
votes
9 answers

Are locks unnecessary in multi-threaded Python code because of the GIL?

If you are relying on an implementation of Python that has a Global Interpreter Lock (i.e. CPython) and writing multithreaded code, do you really need locks at all? If the GIL doesn't allow multiple instructions to be executed in parallel, wouldn't…
Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143
82
votes
18 answers

How to disable Home and other system buttons in Android?

I need to disable Home and other system buttons in my Android application. Example: MX Player (see at Google Play) - you can press "lock" icon at player screen and it locks all hardware and software system buttons. It works fine WITHOUT ROOTING. I…
user1024
  • 1,121
  • 1
  • 9
  • 17
81
votes
2 answers

How do filesystems handle concurrent read/write?

User A asks the system to read file foo and at the same time user B wants to save his or her data onto the same file. How is this situation handled on the filesystem level?
Matteo Riva
  • 24,728
  • 12
  • 72
  • 104
80
votes
5 answers

How to solve SQL Server Error 1222 i.e Unlock a SQL Server table

I am working in a database where I load data in a raw table by a data loader. But today the data loader got stuck for unknown reasons. Then I stopped the data loader from windows task manager. But then I again tried to load data in the raw table but…
user960340
  • 926
  • 1
  • 7
  • 5
80
votes
3 answers

How to find what state ManualResetEvent is in?

I am using an instance of ManualResetEvent to control thread access to a resource but I'm running into problems with it. Does anyone know how I can find out during debugging what the state of the object is? That is to say I would like to know if…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
80
votes
7 answers

Only inserting a row if it's not already there

I had always used something similar to the following to achieve it: INSERT INTO TheTable SELECT @primaryKey, @value1, @value2 WHERE NOT EXISTS (SELECT NULL FROM TheTable WHERE PrimaryKey =…
Adam
  • 952
  • 1
  • 7
  • 11
79
votes
5 answers

Open Image from file, then release lock?

I'm using the following line of code to open an Image from a file: pictureBox1.Image = Image.FromFile("test.png"); I expect it to lock the file, load the image to memory, set pictureBox1.Image to the copy in memory, and release the lock. In…
Eagle-Eye
  • 1,468
  • 2
  • 18
  • 26
79
votes
5 answers

Java Concurrency: CAS vs Locking

I'm reading the Book Java Concurrency in Practice. In chapter 15, they are talking about the nonblocking algorithms and the compare-and-swap (CAS) method. It is written that CAS perform much better than the locking methods. I want to ask the people…
Prine
  • 12,192
  • 8
  • 40
  • 59
78
votes
4 answers

Is Task.Factory.StartNew() guaranteed to use another thread than the calling thread?

I am starting a new task from a function but I would not want it to run on the same thread. I don't care which thread it runs on as long as it is a different one (so the information given in this question does not help). Am I guaranteed that the…
Erwin Mayer
  • 18,076
  • 9
  • 88
  • 126
78
votes
6 answers

How to release possible Postgres row locks?

I ran an update statement on a large PostgreSQL table through the phpPgAdmin interface. This timed out as it ran for too long. I can now update some rows from that table but not all. Trying to update some rows will hang. Are the rows locked? How can…
Liam
  • 19,819
  • 24
  • 83
  • 123
77
votes
11 answers

ZooKeeper alternatives? (cluster coordination service)

ZooKeeper is a highly available coordination service for data centers. It originated in the Hadoop project. One can implement locking, fail over, leader election, group membership and other coordination issues on top of it. Are there any…
76
votes
4 answers

Java : Does wait() release lock from synchronized block

I was under the impression that wait() releases all locks but I found this post which says "Invoking wait inside a synchronized method is a simple way to acquire the intrinsic lock" Please clarify I'm a bit…
Abhijit
  • 812
  • 1
  • 7
  • 7