Questions tagged [locks]
Locks are a synchronization mechanism for enforcing limits on access to a resource.
77
questions
0
votes
0
answers
38
views
Conditional mutex locking
Suppose I have 2 microservices that update some user entities:
One that allows users to interact with their own entities, lets call it service A, and another that iterates through all user entities, ...
-1
votes
1
answer
189
views
Building a function call tree at runtime
Edit #1
I believe that I misrepresented my intent when writing this question by focusing too much on the issues that have arisen from our misuse/misunderstanding of locks. I am making this edit to try ...
4
votes
4
answers
2k
views
What will you do if multiple users access your application at the same time?
I'm an experienced Software Engineer but very weak in concurrency because of no prior experience in that. I've been interviewing with several companies in which I was asked similar kind of questions ...
-1
votes
1
answer
1k
views
Locking a DB table and waiting for writing/reading it from a web application
I'm working on a web application using Spring (Java and JPA + Hibernate) and I was wondering if there is a way of locking a MYSQL table and then when another web service (or even another thread from ...
2
votes
0
answers
184
views
Automatically extended database-based mutex lock - is it a good idea?
Since I am working in a multi-instance microservice environment, I came accross a problem with making some operations being performed at most by one of the running instances at once. The solution ...
1
vote
2
answers
208
views
Locking (reserve) related Aggregate Roots
Problem
In my application a user can lock a set of related aggregate roots to work exclusively on them and to avoid the usage of an invalid set of objects later in the process (by other employees). ...
1
vote
2
answers
676
views
Calling an API and synchronising database
I am calling a payments API to send a payment.
At the same time, I need to mark the payment as sent in my database.
If I call the API first, then the database crashes, the payment will be sent twice.
...
1
vote
2
answers
191
views
Alternatives to pessimistic locking in the DBMS for load balancing
A simplified version of my problem looks like this:
the database contains two tables:
one contains account balances (Accounts)
the other contains account withdrawal and deposit requests (Requests)
...
7
votes
3
answers
506
views
How to replace a file to its latest version in server that is being constantly fetched by a REST API
We have a REST API Get request which downloads a file from the server. This file needs to be updated whenever there is a latest version. Currently this is done by deleting the existing file and moving ...
6
votes
5
answers
5k
views
Why do we need read locks in read-write locks?
in read-write locks, why do we need read locks since processes can read a file at the same time? Would only a write lock suffice? Thanks.
0
votes
2
answers
312
views
My aproach to lockless concurrency
this is a highly theoretical question about my parallelization approach.
First of all, I want to inform everybody that I do not claim that I am the 'inventor' of that approach but I couldn't find any ...
-3
votes
1
answer
68
views
Will this time duration measurement in two threads give correct result?
A program I'm developing has two threads running similar but different task:
thread1:
timer1.start()
writeToExternalDB1(consumedData)
timer1.end()
thread2:
timer2.start()
writeToExternalDB2(...
-1
votes
1
answer
360
views
Is async/await a good alternative for locks in JavaScript?
Yes, I know, the question title is a bit provocatory. But let me explain.
I needed to execute a sequence of async tasks in JavaScript. They are async because I need them to be non-blocking, but I ...
2
votes
2
answers
1k
views
Designing a scalable microservice: how to prevent one instance from performing an action if another instance allready did?
As I am moving a part of the monolith app logic to a microservice, I am standing before a problem with scalability.
Currently, the main monolith runs on different instances, and has some scheduled ...
4
votes
3
answers
781
views
optimistic locking vs pessimistic locking
In the context of a multiuser database desktop application, the concurrency problem has to be considered.
Many articles focus on two models: optimistic and pessimistic locking.
In pessimistic locking ...
0
votes
2
answers
3k
views
Race condition in Distributed Systems
We have a set of micro-services that are functionally dependent and have intertwined validation logic. e.g. consider 'Credit-Card' service and 'Loan' service. When user has a credit card then loan ...
17
votes
3
answers
7k
views
Is there a problem using A LOT of locks in a process?
I'm trying to build a C# application that sends notifications from the server to its users (a mobile app).
Since each user can have its notifications collection changed by any thread, I have to lock ...
0
votes
1
answer
190
views
Locking an item while waiting for human approval
I'm working on adding Approval workflows around our system which manages CRUD operations for our business item.
Till now, I have been using an optimistic locking strategy to handle race conditions ...
1
vote
2
answers
2k
views
Message Queue with multiple consumers locking synchronous on a field
We have a system where multiple consumers get messages out of a queue (currently implemented with a database). The messages have an order field. All messages of one particular order should be ...
2
votes
2
answers
144
views
Name of locking approach
I've seen this approach several times, both in async and multithreaded code. A counter is used to track asynchronous behavior or thread behavior - whenever a new action is started, the counter is ...
1
vote
2
answers
63
views
Ensuring that Lock goes from Process A to Process B
Let's say process A has an exclusive lock on some shared resource. Is there a way to ensure that after it completes execution, Process B will definitely get the lock (as compared to say, process C ...
4
votes
4
answers
2k
views
How to check whether existing code base can deadlock
I'm improving/expanding a somewhat large code base, and I've introduced multithreading into it. But with the possibility of introducing code that could deadlock, which is nigh impossible to test for ...
3
votes
1
answer
229
views
What is the typical best practice methodology around transferring money between two distinct systems?
I got this question on an interview the other day and was clueless to what the best practices are for solving it. It's the issue where you have to transfer money between two systems and want to avoid ...
1
vote
1
answer
219
views
Avoidance of Lost Update in DB2 for z/OS
I have a question concerning the "Uncommitted Read" Isolation Level under DB2 DBMS for z/OS.
In this article
https://www.ibm.com/support/knowledgecenter/en/SSEPEK_11.0.0/perf/src/tpc/...
6
votes
1
answer
1k
views
Why would CPython logging use a Lock for each handler rather than one Lock per Logger?
While developing my own logging library, I studied the source code of the standard logging module of CPython.
One of its features is that handlers are thread-safe. One can write logs to a file from ...
3
votes
2
answers
4k
views
How to handle concurrent updates for the same record in a distributed system
I'm trying to figure out the best solution for the below. Any help would be great.
So basically I have a service (that can be scaled horizontally), which listens on a queue. Every message received ...
1
vote
1
answer
129
views
Inventory management with limited time hold strategy - How do I protect from bad actors?
Some sites, like theater ticket reservations, place a limited-time hold on the item , while the order is being processed. As soon as you select the seat and proceed to pay, Seat is reserved say for 10 ...
0
votes
2
answers
536
views
Optimistic locking with business constraints [closed]
Consider this simple example:
Tables (in a restaurant) can be booked for a period.
Business constraint: No two table bookings for the same table may overlap in time.
How might one prevent business ...
2
votes
1
answer
306
views
Design lease mechanism of shared resource
I have a shared resource in a database that is used by clients C1 and C2. Before the resource is read by C1, C1 should mark the resource as leased so that C2 will know it is busy. C1 will do some ...
2
votes
2
answers
356
views
Achieving very large real-time async writes on MySQL tables without locking them to reads
I am building a webapp (Angular frontend, Groovy/Spring/Hibernate/MySQL backend) that will allow users to compete against each other over certain activities. Each activity will have 1 winner and 1 ...
4
votes
1
answer
2k
views
Automatic blocking/unblocking of allocated seats in a movie ticketing system [closed]
I am trying to build a movie ticketing system. But I am not able to figure out how to solve the below use case:
Let’s say there are 10 seats namely S1,S2,S3,S4… S10.
Now let’s say that User1 had ...
2
votes
3
answers
2k
views
Is the Actor Model an alternative to transactions?
I know that transactions use locks. It is claimed that actors liberate us from shared state and locks
make sure all crashes are the same as clean shutdowns: this can be done through practices such ...
3
votes
2
answers
129
views
Problem related to optimistic locking performance
I'm designing a system that like the majority of social related application has posts, people can like the posts and comment on them.
And also like the majority of the applications the users can see ...
4
votes
1
answer
6k
views
When is it safe to use Monitor (lock) with Task?
In a multi-threaded environment, we must consider concurrent access to writable resources. A common approach is to use Monitor or its shorthand form lock.
Task is at a different abstraction level ...
4
votes
1
answer
1k
views
Race condition allowing multiple transactions; will locking on objects in a dictionary cause issues?
We have a MVC Web API that is called to write transactions for a specific amount, where the amount is debited or credited to a user's balance. This records the balance pre-transaction (PreAmount), the ...
2
votes
2
answers
369
views
When interacting with an ArrayList over REST will a ReadWriteLock maintain consistency?
I have an ArrayList of objects that may be added/deleted/updated via REST calls. In order to prevent issues that may result from concurrent accesses, will a ReadWriteLock be appropriate, and efficient?...
4
votes
1
answer
1k
views
Monitor.Enter() when a thread is of highest priority
Background
Okay, so let's say I have some high priority (ThreadPriority.Highest) thread t which needs to enter a critical region in order to consume some data. I will use the following code snippet ...
3
votes
1
answer
2k
views
Why many programs do not start if pidfile exists but no process is found?
I see a lot of programs that does write a pidfile, and check at boot its existence. And this is good. But many application does not start even if they check that the pidfile exists, yes, but no ...
9
votes
5
answers
1k
views
Composable concurrency in Java or any other programming language
While I was reading a research paper on concurrency named Software and the Concurrency Revolution (html version). I came across following lines:
Unfortunately, although locks work, they pose ...
0
votes
1
answer
198
views
Concurrent languages and non-concurrent dependencies [closed]
We had a bug caused by ruby workers (4 processes, 1 thread each) doing batching records using a legacy mongodb as the store. The race condition was around whether the batch was full or not; with one ...
4
votes
2
answers
732
views
What is it called when threads are waiting but not deadlocked
The definition of a deadlock is when two or more threads cannot complete their execution because they are mutually blocked and waiting for something from the other thread(s).
Is there a similar term ...
3
votes
1
answer
573
views
Minimizing lock time (multithreaded app)
I have a web application written in C# which uses external dll written in C++. Communication between clients (web browsers) and a web application is done using SignalR. For communication between web ...
1
vote
0
answers
43
views
Push instead of pull on a list that might change due to a command in addition to events? [closed]
I need to show a refreshable/searchable list of items and update/add-to it whenever an event is published. How do I make sure no events are lost while refreshing/searching is happening?
Some sort of ...
41
votes
5
answers
6k
views
How is spinlock different from polling?
Is spinlock and polling the same thing?
Wikipedia:
a spinlock is a lock which causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is ...
9
votes
2
answers
6k
views
Why is Akka good for concurrency?
I am new to Akka and actor framework - I am sure I am missing something obvious, please accept my apologies in advance.
I keep reading that one of the main points to choose Akka is the way it manages ...
4
votes
2
answers
538
views
How can I diagram data-locking scenarios?
There are many different types of charts and diagrams we use to formalize scenarios and study them tangibly -- activity diagrams, sequence diagrams, etc.
I've been faced with a pretty complex locking ...
3
votes
1
answer
131
views
Coordinate access to resource between workers
I have a database accessed by an several servers, let's call them workers. These workers take one item from the database, do some operations on it and then update it back into the database. The ...
5
votes
1
answer
4k
views
Does ReaderWriterLockSlim provide thread safety and speed efficiency (compared to a traditional lock) when using a List?
I have a list, to which I write once in every update Loop and then I spawn some tasks which create read that List and create a duplicate to manipulate that data.
More or less it's List.ToList() call ...
13
votes
3
answers
19k
views
Reading file during write on linux
As I understand, when a file is being written, the process writing to the file obtains an exclusive lock. So other processes cannot access this file for read.
With the above knowledge, I'm unable ...
27
votes
3
answers
8k
views
How much work should I place inside a lock statement?
I am a junior developer working on writing an update for software that receives data from a third-party solution, stores it in a database, and then conditions the data for use by another third-party ...