Skip to main content

Questions tagged [locking]

Locking allows different types of resources to be locked by a transaction.

Filter by
Sorted by
Tagged with
4 votes
1 answer
348 views

Did I write the locks properly to prevent concurrency issues?

There may be a dozen things that could be improved about this code, but it's just a very quick proof of concept and for the sake of this post I'm specifically wanting to know if someone can verify ...
BVernon's user avatar
  • 225
2 votes
1 answer
41 views

Distributed locking with fencing token implementation in Golang

I was reading about the implementation of distributed locks where we need to verify the lease using a fencing token as per this article - https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-...
Pratyush Prateek's user avatar
2 votes
3 answers
94 views

Simple rwlock implementation in C

Can someone please review my rwlock implementation to see if there are any issues with correctness (hopefully not), give any feedback on how to write good C code etc, design patterns which could be ...
Tejas Anand's user avatar
4 votes
2 answers
986 views

Distributed lock system using AWS S3

I need a distributed lock system for a service I'm writing. (There can be multiple instances of this service running at a time, and I need to make sure that only one instance does a particular cron ...
threed's user avatar
  • 181
1 vote
1 answer
325 views

Lock Guard Atomic alternative

I've recently written a Vulkan library for creating 2D applications with ease. The catch was I need std::lock_guard for my window resize event to resize resources ...
FatalSleep's user avatar
1 vote
1 answer
166 views

Dart Non-Reentrant Async Lock

This class synchronizes access to an async resource. If retainFutureErrors is false, it will keep retrying until there is a success. Otherwise, the ...
Christian Findlay's user avatar
8 votes
3 answers
2k views

Basic RAII spinlock class

I have written the following class that acts as a simple lock for mutual exclusion: ...
digito_evo's user avatar
0 votes
1 answer
263 views

php flock with timeout (for LOCK_SH / LOCK_EX )

i want a flock with timeout, unfortunately i haven't found a good way to implement it (like a signaled timeout on an actual blocking request?), so i'm just trying and sleeping until success or timeout,...
hanshenrik's user avatar
2 votes
1 answer
188 views

C++20 simple RwSeqLock

I recently discovered the atomic wait/notify mechanism in C++20 and wrote this readers-writer lock in the style of Linux kernel Seqlock. Writes have to be inside a lock/unlock, while reads are ...
MDH's user avatar
  • 23
7 votes
1 answer
498 views

C++ mutex-like class using std::condition_variable

On a project I'm working on, I have a need for a mutual-exclusion primitive behaving like std::mutex or std::recursive_mutex, ...
Macmade's user avatar
  • 171
2 votes
1 answer
194 views

Distributed lock service implementation in Golang

I have multiple E2E tests (written in Java) which share login details, each test during runtime will query the locker API for login details which is running on its own dedicated server. Below is my ...
Pawan Kumar's user avatar
0 votes
1 answer
117 views

Data Wrapper Class with Automatic Saving and Locked Read/Write Accessors

This is a wrapper for a synchronized data structure that: Saves periodically Keeps track of dirty flag automatically (set when a write access is requested) Maintains a lock on data Only allows access ...
CaptainCodeman's user avatar
2 votes
1 answer
1k views

C# lock on string value

Our codebase is full of locks such as: lock("Something." + var) { .... } This causes issues due to strings not meant to be used in locks in this way. ...
Tom Gullen's user avatar
5 votes
3 answers
2k views

Least Recently Used Cache with TTL

I found this problem in a book and found it interesting. wrote this class to implement a Least Recently Used Cache with TTL. Goal - LRU cache with TTL Multithreaded. Functions: Get(key), Put(key,...
user1429322's user avatar
15 votes
2 answers
2k views

Block-free priority lock

Background I wanted to write an event loop that supports scheduling, but found that no implementation of priority queue that I know of supports waiting on a condition variable (the idea is that the ...
Incomputable's user avatar
  • 9,504
0 votes
1 answer
849 views

Simple folder/file lock handler

I have two python scripts (or one bash script + one python script) which are working independently from another, one script puts data into a folder, the other one reads from it. Since I don't want to ...
Matty's user avatar
  • 3
2 votes
1 answer
189 views

Barging lock in Java

I found myself in need of a lock that allows my server to barge the write lock that might be acquired by my users. It would never interrupt them, but it would jump the line so the next time the write ...
corsiKa's user avatar
  • 660
2 votes
1 answer
413 views

C++ implementation of recursive_shared_mutex

I know it's bad to even use recursive_mutex because of its poor performance, let alone a recursive shared mutex. However, I'm doing this just to practice. Any suggestion will be appreciated! ...
Einiemand's user avatar
  • 243
5 votes
2 answers
2k views

Implementing Multi Producer Multi Consumer Simple Thread Safe Class

I am learning C# and in the process I am trying to implement a multi producer consumer thread safe class. Can you please code review and point me to any mistakes I have made and improvements I can ...
anands's user avatar
  • 53
6 votes
1 answer
4k views

Blocking Queue in C++ using semaphores

This is mostly an exercise for me to try to understand the differences between semaphores and locks. It's a long and rambling because it took me quite a few tries to understand the concepts. Please ...
wgemini's user avatar
  • 61
7 votes
1 answer
1k views

Is Lock necessary to make operation thread safe for this scenario

I have the following method that is responsible for retrieving an Item from the database. There will be multiple threads instantiating this class, so I want to make ...
whoami's user avatar
  • 175
1 vote
1 answer
218 views

Thread-safe event-queue code appears to work, any possible race conditions, deadlocks, or other design problems?

Cross-Posted from Stack Overflow I am new to using condition_variables and unique_locks in C++. I am working on creating an ...
PMARINA's user avatar
  • 113
2 votes
1 answer
393 views

Is this C++11 seqlock implementation correct?

My code: https://ideone.com/DZeIZv ...
gavv's user avatar
  • 121
1 vote
1 answer
433 views

Is this locked use of a Java HashMap thread safe?

I am trying to improve the performance of one of my project's methods, which obtains the command line of a process using WMI. A summary of key points: The method is on an object representing a ...
Daniel Widdis's user avatar
1 vote
1 answer
310 views

Dictionary for locking on unique identifiers without leaking memory

The following code is greatly inspired on this question and this answer. That answer works quite well for a specific case, but I was looking for a solution that: could be used more generic (so I can ...
Dirk Boer's user avatar
  • 650
5 votes
0 answers
60 views

Lightweight lock using OMP atomic

I am working on a Monte Carlo simulation using OpenMP multithreading. To avoid race conditions when multiple threads work on the same resolution element, I have implemented the following ...
user35915's user avatar
  • 151
4 votes
0 answers
111 views

Implementation of a time lock with Python's asyncio

I have no idea if this kind of lock is called time lock, but I need something for the following scenario: I'm making a lot of concurrent requests with aiohttp, and ...
rubik's user avatar
  • 503
3 votes
1 answer
160 views

Pidfile single process instance mechanism

I'm writing a system daemon in Rust that may be started by the user manually. Only one instance of the daemon should be running at a time so I have created a pidfile locking mechanism to prevent ...
Fyrn's user avatar
  • 33
1 vote
0 answers
980 views

First readers-writers problem using a single condition

For the first readers-writers problem, in which readers can access a given resource simultaneously, is the following Python3 solution correct? Problem parameters: One set of data is shared among a ...
Pedro Lopes's user avatar
2 votes
0 answers
98 views

Comparing Java Semaphore versus ReentrantReadWriteLock

In this post, I attempted to compare the performance of two concurrency constructs: java.util.concurrent.Semaphore, ...
coderodde's user avatar
  • 29.1k
3 votes
2 answers
3k views

An attempt of replacing CRITICAL_SECTION with std::mutex and std::lock_guard

I have an older class that I am working on and I'm updating it to remove "Windows" specific code. It had some "Thread Protection Code" that used CRITICAL_SECTION. I'...
Francis Cugler's user avatar
0 votes
1 answer
101 views

Managing locking for access

I've been working for a while on locking resources (state objects) so that the only way to access them is by acquiring a lock. This moves the responsibility for locking from the user of the state to ...
kofifus's user avatar
  • 101
5 votes
2 answers
444 views

Implementing lock within a Python script

I've written a script in Python using multiprocessing to handle multiple process at the same time and make the scraping process faster. I've used locking within it to prevent two processes from ...
SIM's user avatar
  • 2,501
5 votes
2 answers
1k views

Using lock with value type (multithread context)

I have to use value type to lock code sections in correspondence to objects identifiers (i.e. Guid, int, ...
lemon's user avatar
  • 153
5 votes
1 answer
300 views

Script to clean up old files that should only run one instance

I'm writing a bash script for deleting old files on a Linux server. Here are some relevant facts about this script: As currently written, it does work as expected. However, it's entirely possible ...
JesseTG's user avatar
  • 459
4 votes
3 answers
3k views

C++ upgradable RW lock implementation

I am using VS 2017 with C++ 17 standard set on Windows OS. What I'm missing in couple of heavily threaded projects is synchronizing mechanism that can be atomically upgraded from shared to exclusive ...
Milos Ljumovic's user avatar
3 votes
2 answers
826 views

Circular / Cyclic Buffer implementation

I am learning circular / cyclic buffer using this link. Here is the code that I have written so far: ...
skr's user avatar
  • 539
1 vote
1 answer
140 views

Concurrent usage of resources

Please take a look at the following code. This is my attempt at understanding concurrent applications. ...
Dmitry Volkov's user avatar
10 votes
1 answer
2k views

Snowflake Id implementation

For some time now I have maintained (and written) IdGen. It's inspired by Twitter's Snowflake project and it's intended use is to generate (roughly) incremental id's in a distributed scenario with ...
RobIII's user avatar
  • 195
4 votes
1 answer
6k views

Simple rwlock implementation in c++11

For answering this question of stackoverflow I have written the code https://stackoverflow.com/questions/12033188/how-would-you-implement-your-own-reader-writer-lock-in-c11 Can someone review it - ...
Rishi Agrawal's user avatar
3 votes
3 answers
1k views

Threadsafe Stack

Here is a class which I have written to create a simple Stack data structure which can be shared across multiple threads. It's a simple LIFO which has 2 operations: one to push onto the top of the ...
AbNig's user avatar
  • 141
2 votes
1 answer
95 views

Keeping the average user from opening two copies of my program

I know that this is an impossible task against someone determined, but I'd like to keep mid-average users from being able to open more than one copy of my program at a time. Here's the quick code I'...
Ottomated's user avatar
5 votes
2 answers
4k views

Check for timeout in wait() loop

I want to check for a condition in a guarded wait() loop with a user-specified total timeout, similar to how ...
Mark Jeronimus's user avatar
3 votes
1 answer
4k views

Reader Writer Lock Implementation

I'm practicing to write c++11/14 and I implemented a RW lock. Does everything look ok? ...
user3666471's user avatar
2 votes
1 answer
2k views

Release the acquired lock after specific timeout

I'm trying to release a lock after some timeout. The lock is acquired to do any database changes so that multiple requests will ...
Rudresha Parameshappa's user avatar
7 votes
1 answer
5k views

Preventing duplicate key errors in EF-Core InMemory provider through locking

I have a rest service on Azure AD that calls other rest services. They use AzureAd authentication and AuthContext with a custom TokenCache that stores each users ...
Justin Dearing's user avatar
4 votes
1 answer
97 views

ReadWriteSerializer

I am developing a C++ kernel, and I've got the need for manipulating huge data structures before the task-scheduler runs - it means in a non-preemptive environment. For this, I have developed a read-...
Shukant Pal's user avatar
3 votes
2 answers
87 views

SharedMutex concept implementation

I was curious to implement something similar to SharedMutex concept. So far only 4 methods implemented. I decided to omit try_lock, ...
triclosan's user avatar
  • 244
3 votes
2 answers
2k views

Shared disposable object, where only one can exist at a time

In my program I need to impersonate users on the domain network to perform various tasks. Obviously I can only be one user at a time, and there are multiple threads that would like to be either the ...
Jean-Bernard Pellerin's user avatar
1 vote
0 answers
1k views

C++11 CLH Lock Implementation

As a hobbyist programmer I have been reading "The Art of Multiprocessor Programming" (Herlihy, Maurice; Shavit, Nir) and converting the Java spin locks into C++ - I have enjoyed this and learned a lot....
headwedge's user avatar