Questions tagged [locks]

A lock generally refers to something that prevents another process from starting or accessing the same information until the lock is released. Use with an appropriate language tag. Do not use for physical locks.

433 questions
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
52
votes
12 answers

Are Locks AutoCloseable?

Are Locks auto-closeable? That is, instead of: Lock someLock = new ReentrantLock(); someLock.lock(); try { // ... } finally { someLock.unlock(); } ...can I say: try (Lock someLock = new ReentrantLock()) { someLock.lock(); //…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
38
votes
3 answers

Dropping table makes MySQL hang

When I try to drop a table, MySQL hangs. I don't have any other open sessions. How to resolve this? I have waited for 10 hours and the process has not terminated.
cool_cs
  • 1,661
  • 6
  • 20
  • 26
26
votes
1 answer

Status of mixing multiprocessing and threading in Python

What are best practices or work-arounds for using both multiprocessing and user threads in the same python application in Linux with respect to Issue 6721, Locks in python standard library should be sanitized on fork? Why do I need both? I use…
ricopan
  • 662
  • 6
  • 13
23
votes
5 answers

Unlocking lock owned by another thread java

I have a LockManager that manages the locks of several threads. Sometimes the threads are bad boys, and I have to kill them and ask the LockManager to release all their locks. However, since I use ReentrantLock in java this is impossible, I can not…
Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
22
votes
6 answers

Creating a standard map that is thread safe

In my current scenario speed is essential I have a map that is only being read by multiple threads and this works fine. Now a requirement came up that may require writing to the static map once in a while while the maps are being read by other…
MistyD
  • 16,373
  • 40
  • 138
  • 240
19
votes
2 answers

MySQL InnoDB locks on joined rows

Does "SELECT ... FOR UPDATE" lock joined rows in MySQL? If so, is it possible to disable this behaviour? There is nothing about this in the documentation. I've seen that Oracle supports "SELECT ... FOR UPDATE OF table_name" where table_name is the…
Miloš Rašić
  • 2,229
  • 5
  • 24
  • 43
15
votes
1 answer

Microsoft SQL Server Management Studio - Alerts with additional information of lock

We want to have an alert when a lock is waiting longer than 60 seconds. The alert script below is performing as expected. But we'd like to have more information like the locked Session ID, Locking Status, login name, etc. Is there a way to include…
Rogier
  • 905
  • 1
  • 10
  • 25
15
votes
5 answers

Why setArray() method call required in CopyOnWriteArrayList

In CopyOnWriteArrayList.java, in the method set(int index, E element) below: public E set(int index, E element) { final ReentrantLock lock = this.lock; lock.lock(); try { Object[] elements = getArray(); Object oldValue =…
Pushparaj
  • 1,039
  • 1
  • 6
  • 26
14
votes
1 answer

What are intention shared and intention exclusive locks in mongodb?

Can anyone explain intention shared and intention exclusive locks in mongodb by examples? I read about their functionality but I can't figure out what are their actual usage in real db examples. Update: (More information) Assumption: mongodb…
Maryam Saeidi
  • 1,463
  • 2
  • 21
  • 33
14
votes
2 answers

mysql - do locks propagate over replication?

I have a Mysql master-slave(s) replication with MyISAM tables. All updates are done on the master and selects are done on either the master or slaves. It appears that we might need to manually lock a few tables when we do certain updates. While…
adamSpline
  • 483
  • 4
  • 13
13
votes
1 answer

Python: Can I use class variables as thread locks?

I was thinking about using a class variable as a thread lock, since I don't like to define a lock within the global variables and also want to prevent deadlock. Does this actually work? Example: import threading class A(object): lock =…
Torsten Engelbrecht
  • 13,318
  • 4
  • 46
  • 48
11
votes
2 answers

How locks are implemented on multiple cores

For a uni-processor, the lock algorithm is pretty simple. Lock(threadID) { Disable Interrupts If lock is already owned by same thread{ Restore Interrupts return } if lock is free { make lock busy set current thread as the…
user447851
  • 163
  • 2
  • 6
11
votes
1 answer

SELECT ... FOR UPDATE SKIP LOCKED in REPETABLE READ transactions

I have the following statement in my PostgreSQL 10.5 database, which I execute in a repeatable read transaction: delete from task where task.task_id = ( select task.task_id from task order by task.created_at asc limit 1 for…
Ynv
  • 1,824
  • 3
  • 20
  • 29
10
votes
2 answers

Why does Python provide locking mechanisms if it's subject to a GIL?

I'm aware that Python threads can only execute bytecode one at a time, so why would the threading library provide locks? I'm assuming race conditions can't occur if only one thread is executing at a time. The library provides locks, conditions, and…
danihodovic
  • 1,151
  • 3
  • 18
  • 28
1
2 3
28 29