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
196
votes
29 answers

Git 'fatal: Unable to write new index file'

I've seen many of the other threads about this and they don't help. I have a very simple repo - two JavaScript files. I have 100+ GB on Macbook. When I try to move the files into a subdirectory and stage locally the changes I get ... fatal: Unable…
Jeff
  • 13,943
  • 11
  • 55
  • 103
185
votes
7 answers

What are the differences between various threading synchronization options in C#?

Can someone explain the difference between: lock (someobject) {} Using Mutex Using Semaphore Using Monitor Using Other .Net synchronization classes I just can't figure it out. It seems to me the first two are the same?
user38834
  • 1,859
  • 3
  • 12
  • 3
169
votes
10 answers

Any way to select without causing locking in MySQL?

Query: SELECT COUNT(online.account_id) cnt from online; But online table is also modified by an event, so frequently I can see lock by running show processlist. Is there any grammar in MySQL that can make select statement not causing locks? And…
omg
  • 136,412
  • 142
  • 288
  • 348
165
votes
8 answers

How to detect query which holds the lock in Postgres?

I want to track mutual locks in postgres constantly. I came across Locks Monitoring article and tried to run the following query: SELECT bl.pid AS blocked_pid, a.usename AS blocked_user, kl.pid AS blocking_pid, ka.usename AS…
Roman
  • 64,384
  • 92
  • 238
  • 332
156
votes
24 answers

Make sure only a single instance of a program is running

Is there a Pythonic way to have only one instance of a program running? The only reasonable solution I've come up with is trying to run it as a server on some port, then second program trying to bind to same port - fails. But it's not really a…
Slava V
  • 16,686
  • 14
  • 60
  • 63
150
votes
8 answers

Find out who is locking a file on a network share

I want to known who is locking a file on a network share. Here is the problem : the network share is on a NAS, so I can't log on. I need a tool to find out remotely who is locking the file. It is not practical to reboot the NAS every time, because…
olorin
  • 2,214
  • 3
  • 19
  • 22
145
votes
1 answer

Notepad beats them all?

On a Windows Server 2012 R2 system, a Kotlin program uses FileChannel.tryLock() to hold an exclusive lock on a file, like this: val fileRw = RandomAccessFile(file, "rw") fileRw.channel.tryLock() With this lock in place, I cannot open the file…
MonoThreaded
  • 11,429
  • 12
  • 71
  • 102
139
votes
7 answers

MySQL: Transactions vs Locking Tables

I'm a bit confused with transactions vs locking tables to ensure database integrity and make sure a SELECT and UPDATE remain in sync and no other connection interferes with it. I need to: SELECT * FROM table WHERE (...) LIMIT 1 if (condition…
Ryan
  • 17,511
  • 23
  • 63
  • 88
139
votes
5 answers

How to prevent screen lock on my application with swift on iOS

How can I prevent screen lock only when using Navigation? Waze has the option to do that, how can I do this in my App?
alvarogalia
  • 1,601
  • 2
  • 12
  • 10
139
votes
5 answers

What's the difference between an exclusive lock and a shared lock?

According to wikipedia: Shared locks are sometimes called "read locks" and exclusive locks are sometimes called "write locks". Can you explain the reasoning behind the terms "shared" and "exclusive"?
Rose Perrone
  • 61,572
  • 58
  • 208
  • 243
134
votes
3 answers

Why does the lock object have to be static?

It is very common to use a private static readonly object for locking in multi threading. I understand that private reduces the entry points to the locking object by tightening the encapsulation and therefore access to the most essential. But why…
Houman
  • 64,245
  • 87
  • 278
  • 460
132
votes
4 answers

Re-entrant locks in C#

Will the following code result in a deadlock using C# on .NET? class MyClass { private object lockObj = new object(); public void Foo() { lock(lockObj) { Bar(); } } public void Bar() …
Guy
  • 65,082
  • 97
  • 254
  • 325
132
votes
4 answers

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

I always get confused. Would someone explain what Reentrant means in different contexts? And why would you want to use reentrant vs. non-reentrant? Say pthread (posix) locking primitives, are they re-entrant or not? What pitfalls should be avoided…
vehomzzz
  • 42,832
  • 72
  • 186
  • 216
131
votes
7 answers

How expensive is the lock statement?

I've been experimenting with multi threading and parallel processing and I needed a counter to do some basic counting and statistic analysis of the speed of the processing. To avoid problems with concurrent use of my class I've used a lock statement…
Kees C. Bakker
  • 32,294
  • 27
  • 115
  • 203
120
votes
3 answers

Intermittent log4net RollingFileAppender locked file issue

We are seeing an intermittent issue on development and production machines whereby our log files are not getting logged to. When running in development and debugging using Visual Studio we get the following log4net error messages in the VS output…
Richard Ev
  • 52,939
  • 59
  • 191
  • 278