Questions tagged [locks]

Locks are a synchronization mechanism for enforcing limits on access to a resource.

Locks are a synchronization mechanism for enforcing limits on access to a resource.

Further Reading

77 questions
41
votes
5 answers

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 available This sounds awfully lot…
Lord Loh.
  • 1,767
  • 1
  • 14
  • 22
40
votes
5 answers

Does immutability entirely eliminate the need for locks in multi-processor programming?

Part 1 Clearly Immutability minimizes the need for locks in multi-processor programming, but does it eliminate that need, or are there instances where immutability alone is not enough? It seems to me that you can only defer processing and…
28
votes
6 answers

Best-practice to manage concurrency into a basket in a e-commerce website

What is the best practice to manage the case where two customers add in the same time a product whose the stock was only 1 ? Must there be a check in the code of the basket to avoid one of these 2 customers to add the same product ? Or does this…
Mik378
  • 3,838
  • 7
  • 33
  • 60
27
votes
3 answers

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 solution. Our software runs as a Windows…
Joseph
  • 393
  • 4
  • 7
27
votes
4 answers

What prevents a race condition on a lock?

I understand the basics of what data races are, and how locks/mutexes/semaphores help prevent them. But what happens if you have a "race condition" on the lock itself? For example, two different threads, perhaps in the same application, but running…
Gavin D. Howard
  • 1,020
  • 1
  • 10
  • 11
17
votes
3 answers

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 those collections whenever somebody tries to…
Idov
  • 279
  • 2
  • 5
13
votes
3 answers

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 to understand how I'm able to play a video in media…
Sorter
  • 373
  • 2
  • 4
  • 12
13
votes
1 answer

Best practise is not to poll...but isn't polling happening internally anyway when a thread calls wait()?

Say we have some thread that wants to check when another thread is finished its task. I have read that we should call a wait() type function that will make this thread wait until it receives a notification that the other thread is finished. And that…
csss
  • 231
  • 2
  • 5
10
votes
4 answers

PHP file_put_contents File Locking

The Senario: You have a file with a string (average sentence worth) on each line. For arguments sake lets say this file is 1Mb in size (thousands of lines). You have a script that reads the file, changes some of the strings within the document (not…
hozza
  • 293
  • 1
  • 3
  • 12
9
votes
5 answers

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 serious problems for modern software development. A…
user183296
9
votes
2 answers

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 concurrency. It is not clear to me why Akka is…
abx78
  • 415
  • 4
  • 10
7
votes
3 answers

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 the latest file as new one. As the file is being…
Anjo
  • 215
  • 1
  • 6
7
votes
4 answers

Is Using Locking/Unlocking in Version Control an Anti-Pattern?

Recently I've started using Git at work. Previously I've only ever used VSS (which has some problems) and so far, Git is orders of magnitude better. The key differences here is that Git is distributed while VSS has a centralized "server" version,…
joshin4colours
  • 3,678
  • 1
  • 24
  • 37
6
votes
1 answer

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 multiple threads without the risk that the lines…
Delgan
  • 366
  • 2
  • 13
6
votes
6 answers

What is the actual reason that locks (sentinels) in OO are hard to reason about?

In this talk, Rich Hickey introduces Clojure. He gives an Ants demo and talks about his motivations for implementing a Software Transactional Memory (STM) system. His reasoning for STM is that "locks are hard to reason about". I took that to mean…
hawkeye
  • 4,819
  • 3
  • 24
  • 35
1
2 3 4 5 6