8,916 questions
3
votes
1
answer
247
views
How to guarantee pg_advisory_xact_lock execution order?
We are extensively using Postgres advisory locks to re-centralize a distributed software system to publish to an API which requires aggregated data.
Rarely, multiple locks have to be acquired which we ...
Advice
1
vote
8
replies
146
views
Using advisory locks to coordinate database activity
I have several different jobs that can run throughout the day to read data from various sources and update my database.
I want to ensure that two jobs are not trying to update the database at once. ...
1
vote
1
answer
90
views
virtualxid lock during reindex operation [closed]
I am trying to do reindex concurrently on a table, but when I see pg_stat_activtity it shows in Lock state with Virtualxid as wait_event.
It's tableA on which the reindex is being performed, but the ...
1
vote
2
answers
426
views
Are the lock and unlock methods of a mutex object considered as modifications to the object?
[thread.mutex.requirements.mutex.general] p4 says
For purposes of determining the existence of a data race, these behave as atomic operations ([intro.multithread]). The lock and unlock operations on ...
1
vote
1
answer
132
views
How to set timeout for function execution in postgresql?
I've received a task to optimize our function for generating new partitions for a table.
Let's say that we have something like this:
CREATE OR REPLACE FUNCTION partition_creator(count_days integer, ...
2
votes
0
answers
155
views
Bypass Windows global lock in NtUser* functions?
We are using Windows 11 24H2 in our test system. There we start multiple instances of our GUI application (WinForms, .NET Framework 4.8) on each machine. The application is controlled via COM scripts ...
2
votes
0
answers
92
views
Readers-writer spinlock implementation for lab locks MIT OCW OS
I am trying to learn some operating system engineering so I came about MIT's operating system engineering course which has been wonderful so far.
The problem I'm having is with the second problem read-...
0
votes
1
answer
153
views
Git .lock file not found
I am trying to do a git fetch (or any other Git command) and I get the following error:
fatal: Unable to create '/path/to/repo/.git/refs/remotes/origin/main.lock': File exists.
There are no .lock ...
Advice
2
votes
6
replies
178
views
Cheap Locking for a thread that is 99.999999999% owner
I have a function that updates the state of some shared resource.
99.999999999% of the time, this function is only called from a single thread.
I want a cheap way for this thread to check for other ...
0
votes
1
answer
65
views
Can I remove the pg_try_advisory_lock() call for function run_maintenance_proc() generated by pg_partman extension?
Why does the PostgreSQL run_maintenance_proc need pg_try_advisory_lock? Can I remove that? It keeps creating table deadlocks.
Its probably because I am also using dbt to generate a few materialized ...
2
votes
1
answer
120
views
Can't use lock around gather in Python asyncio
For some reason, this code doesn't work on Ubuntu 20, Python 3.8.10, unless the .gather line is commented out.
It works on Ubuntu 24, Python 3.12.3 and Windows 11, Python 3.13.9.
It doesn't work on ...
Advice
1
vote
13
replies
6k
views
C# - lock multiple methods or entire class to single thread execution
I am trying to ensure that methods in my class can only be called by a single thread.
So far tried to use ReaderWriterLockSlim to achieve this effect but this can cause potential issues if it is not ...
Advice
0
votes
1
replies
58
views
How to handle high contention at scale?
We’re building a system where an offer can be redeemed until a global limit is reached.
For example, an offer may allow a maximum total redeemable amount (e.g., 10M), or/and only allow each user to ...
2
votes
1
answer
47
views
Do redisson locks, which are distributed, work as single JVM locks as well
I am using RLockReactive from redisson to get the redis distributed lock, then performing a Supplier operation.
The Supplier runs 2 steps in sequence, but I am seeing that while the lock is kept ...
6
votes
1
answer
407
views
Is it possible to build a mutex from C++20 std::atomic without spinning to avoid use-after-free when deleting?
Before I get to my main question, I'm assuming that std::mutex::unlock() stops touching this as soon as it puts the mutex in a state where another thread might lock it - even though the call to unlock(...
0
votes
0
answers
84
views
How to not lock tables in an ODBC connection?
I'm working on a Node.js project that reads data from an HFSQL database. I'm using the odbc library to create a simple connection like this:
connection = await odbc.connect("DSN=xxxxx;UID=xxxxx;...
1
vote
1
answer
204
views
Is sequentially consistent memory ordering strictly necessary in this readers-writers lock using only load/store, not RMW?
Consider this outline of a simple multi-threaded application. It has one writer thread, and ten reader threads.
#include <atomic>
#include <thread>
const int Num_readers{...
1
vote
1
answer
117
views
Why pthread_rdlock doesn`t downgrade the lock?
Code:
pthread_rwlock_wrlock(&memlock); // (1)
// do something...
pthread_rwlock_rdlock(&memlock); // (2)
// do something...
pthread_rwlock_wrlock(&memlock); // (3)
The following tags, (1),...
3
votes
1
answer
143
views
Is it thread-safe to use std::atomic<bool> to control access to a data structure cooperatively, with just loads/stores instead of RMW?
I'm playing around with lockless C++ programming, and I came up with a method for safely(?) transferring ownership of a non-thread-safe data structure (std::unordered_map<int, float> in my ...
1
vote
2
answers
194
views
Different locking behavior betweeen running query from code with @Transactional and running on SQL Server
I have created the following test scenario:
CREATE TABLE master.mytest.control_table (
id int IDENTITY(1,1) NOT NULL,
uuid varchar(36) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
status ...
2
votes
1
answer
89
views
Do explicit locks in postgresql CTEs lock every row even with a cursor?
Let's say I have a table
CREATE TABLE mytable (
user_id bigint,
someval text
)
In my application, I want to lock and fetch every row for some given user_id e.g. 123 to do some additional ...
2
votes
0
answers
111
views
How to avoid double checks with asyncio.Lock
I have a piece of code, that checks if the redis db has data updates and loads them to the memory. I want only one corouitine to execute this load.
class MyService:
def __init__(self):
...
3
votes
1
answer
2k
views
import sentence_transformers hangs on macOS with [mutex.cc] RAW: Lock blocking error
I'm encountering a persistent issue where importing the sentence_transformers library on macOS causes my Python script to hang indefinitely. When the script hangs, the only output I see is a low-level ...
0
votes
0
answers
56
views
How to build a "lock-screen" app for Android 11 that re-appears after N seconds of inactivity?
I’m writing a prototype app for Android 11 (API 30, runs on MFP) that has to behave in the following manner:
A background component that determines when a user has been inactive for N seconds.
A ...
0
votes
1
answer
81
views
How to concurrently remove lines from a file in Python?
I have a cluster of compute nodes, each node with many CPUs. I want them to execute commands located in a file, one command per line. The drive where the command file is located is mounted on all ...
1
vote
2
answers
119
views
How to write a panic message if the UART is already locked by the panicking code?
I'm working on a hobby RISC-V OS kernel (QEMU virt) in no_std Rust and want my panic_handler to print the panic information to UART (is it the right way?).
My println! macro eventually calls a _print ...
0
votes
2
answers
163
views
How to lock database fields for all containers with Java
Concurrent Access to Database Records in Quarkus
I have a Quarkus application with two containers that are accessing the same database records on a schedule. The records have a field that is marked as ...
0
votes
0
answers
71
views
Is Lost Update without certification failure expected in Galera Cluster?
I'm using a multi-node Galera Cluster and encountered the following two scenarios:
Case 1 — Certification Conflict (Deadlock) occurs:
Node B and Node C both start transactions.
Both try to update the ...
1
vote
0
answers
21
views
Can't see lock on table begin truncated in PostgreSQL
I am truncating a large table - a few Terrabytes in size. To ensure that there are no locking issues, I executed the following query in another window and the results are also there. Why isn't the ...
2
votes
1
answer
208
views
Configure lock_timeout in Rails application for reindexing outside migrations
In a Rails application using Postgres 16, I'm working on an automated process to detect indexes with high fragmentation, and reindex them whenever a certain threshold is reached. I'm not having any ...
1
vote
3
answers
167
views
Why is the lock in Rust held throughout the `if let` block? [duplicate]
Call Mutex.lock() after if let. This lock will be held inside the whole if let block.
If we lock again in the if let block. It's deadlock. This also happen for RwLock.
use std::sync::Mutex;
fn main() {...
3
votes
1
answer
644
views
Python 3.13 Threading lock.acquire vs lock.acquire_lock
In Python 3.13 (haven't checked lower versions) there seem to be two locking mechanisms for the threading.Lock class. I've looked online but found no mentions of acquire_lock or release_lock and ...
1
vote
1
answer
100
views
Lock a row in a trigger
I have two PostgreSQL tables: objects and metadata. Each object has a size property that represents its size in bytes and can be stored in a unique location with storage_id. In metadata, the ...
2
votes
1
answer
103
views
Python asyncio Lock.release(): object NoneType can't be used in 'await' expression
Code & Context
I'm building a multithreaded program to automate API calls, to retrieve all the information I need based off of a list of unique IDs.
To do this, I ended up creating my own Lock ...
0
votes
0
answers
33
views
Implementing Lock Feature After Writing to NFC Tag
I am currently facing an issue related to locking an NFC tag after writing data to it. By "locking," I mean making the tag's data read-only, so that once the data is written, it cannot be ...
0
votes
0
answers
40
views
Oracle 19c: how to delete file locked by UTL_FILE() package
Oracle 19c on Windows 2022.
Is there a way to delete a .csv file that was locked by UTL_FILE() process that failed mid-way?
I tried to
rename it,
LockHunter,
UTL_FILE.CLOSE_ALL;
, but all w/out ...
0
votes
1
answer
138
views
Does Dynamodb TransactWriteItem use lock?
In Dynamodb paper 2022 https://www.usenix.org/system/files/atc23-idziorek.pdf, it's said that Transactions do not acquire locks. However in pseudo code in Listing 4
def processCommit ( CommitInput ...
2
votes
1
answer
319
views
Is a lock needed when multiple tasks push into the same asyncio Queue?
Consider this example where I have 3 worker tasks that push results in a queue and a tasks that deals with the pushed data.
async def worker1(queue: asyncio.Queue):
while True:
res = ...
2
votes
1
answer
166
views
File based lock to control read-only or read-write access to a file or directory
I am writing a Kotlin/JVM Gradle plugin that stores data in an application-cache directory, so the data can be shared across separate projects. I need to ensure the contents are not modified while ...
1
vote
0
answers
59
views
Locking a json file across 2 independent processes - a comparison of two methods
(I know that this question has come up several times on Stack Overflow already, but I still think it is worth clarifying some details.)
Suppose that there are two independent Python processes: a.py ...
2
votes
1
answer
275
views
Why can't I return a std::lock_guard? How can I work around it?
I'm trying to return a std::lock_guard by value. The following works fine using an online compiler (programiz), but in Visual Studio 2017 using C++17, lock1() below won't compile because I'm ...
2
votes
0
answers
89
views
Memory Lock Without Atomic RMW Operations
I'm working with a fiber-optic reflective memory card (RFM2g model), which lacks atomic read-modify-write operations. My goal is to implement a spinlock across multiple processes (potentially running ...
2
votes
2
answers
106
views
What happens when application thread shuts down while having a row lock in postgresql?
If application has acquired row lock and is performing transaction, when shut down (eg. power outage) what will happen to the locked row? Is the lock turned off and whole transaction is rolled back?
6
votes
4
answers
238
views
Difference between if statement initializers taking a lock
I need to get a lock only during evaluation of the if statement condition.
The lock must be released when running the code inside the if or else statements.
I found a piece of code and I don't know if ...
0
votes
1
answer
127
views
How lock table editing with MS Access front, SQL Server back?
I am implementing pseudo-locking in an Access project. I have a table, tblLock which holds the lock records (includes the area being locked, the user, a timestamp).
I could simply rely on this table ...
0
votes
1
answer
74
views
Preventing Multiple Concurrent Requests in Node.js with Async/Await and some sort of Lock
Improving Authentication Lock to Prevent Multiple Concurrent Requests
I have a Node.js server that acts as a reverse proxy to my partner APIs. My mobile app makes 3 concurrent requests to my Node ...
-3
votes
1
answer
116
views
Can a unique_lock and a normal lock cause together a dead-lock?
I'm using unique_locks and normal lock to lead the threads. I try to interlink the threads, so they don't loose too many cycles and work together and not separately.
I don't know, if my code can ...
0
votes
1
answer
166
views
Postgres vs MySQL index locking: Should I expect MySQL to be more tolerant to parallel write-heavy applications? [closed]
Postgres doc says:
B-tree, GiST and SP-GiST indexes
Short-term share/exclusive page-level locks are used for read/write access. Locks are released immediately after each index row is fetched or ...
0
votes
2
answers
88
views
Liquibase Double-Checked Locking Pattern ? (make liquibase not acquiring lock if everything is up-to-date)
If an application crashes (OOM / power failure / kill -9) after liquibase acquired a lock, but before releasing the lock, the lock will remain in the databasechangeloglock table forever and we'll need ...
0
votes
2
answers
140
views
python main thread slow down with started second while loop thread
I have problem with following code. I started new thread which have empty while loop.
It causes that function psutil.net_connections() is executed slowly. I need to wait about 1 minute to get result.
...