Questions tagged [locking]

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

Filter by
Sorted by
Tagged with
5
votes
0answers
29 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 ...
4
votes
0answers
50 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 ...
3
votes
1answer
48 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 ...
1
vote
0answers
57 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 ...
2
votes
0answers
36 views

Comparing Java Semaphore versus ReentrantReadWriteLock

In this post, I attempted to compare the performance of two concurrency constructs: java.util.concurrent.Semaphore, ...
1
vote
0answers
104 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'...
1
vote
0answers
64 views

Critical section around given key

I would like to know if there is any pre-existing implementation of my solution so I don't have to reinvent the wheel. What I'm trying to create is an utility which allows me to create critical ...
0
votes
1answer
94 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 ...
5
votes
2answers
259 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 ...
5
votes
2answers
172 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, ...
4
votes
1answer
50 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 ...
1
vote
0answers
54 views

Using ReadWriteLock to implement a cache access guard

In my project, there is an internal cache api to use. I have noticed an emerging pattern such that: ...
3
votes
3answers
325 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 ...
3
votes
2answers
208 views

Circular / Cyclic Buffer implementation

I am learning circular / cyclic buffer using this link. Here is the code that I have written so far: ...
1
vote
1answer
116 views

Concurrent usage of resources

Please take a look at the following code. This is my attempt at understanding concurrent applications. ...
7
votes
1answer
354 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 ...
3
votes
1answer
1k 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 - ...
3
votes
3answers
522 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 ...
2
votes
1answer
83 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'...
2
votes
1answer
2k 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 ...
2
votes
1answer
2k views

Reader Writer Lock Implementation

I'm practicing to write c++11/14 and I implemented a RW lock. Does everything look ok? ...
1
vote
1answer
100 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 ...
6
votes
1answer
2k 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 ...
3
votes
1answer
71 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-...
3
votes
2answers
61 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, ...
3
votes
2answers
1k 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 ...
1
vote
0answers
396 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....
4
votes
0answers
77 views

Delegated condition_variable against spurious wakeup

This is my attempt at dealing with spurious wakeups: A new class which replaced std::condition_variable in my code. Some questions which came to my mind are (and I ...
2
votes
1answer
355 views

Two-layer RAII to support a critical section

For the code, if one considers using RAII to encapsulate CriticalSection (global scope), two RAII layers are needed: ...
1
vote
1answer
714 views

Dining Philosopher's problem implementation with Java Locking Framework to avoid deadlock

Dining philosopher problem is one of the classic problems in computer science. I intended to implement it using Java threads. I attempted using the locking framework that came with Java 5 and used the ...
0
votes
1answer
100 views

Pool of two objects for a web service

I am creating a web service that uses a component I've licensed that is restricted to two concurrent instances at any one time. Creating a new instance of the component takes a long time (seconds) so ...
1
vote
0answers
92 views

AsyncLock implementation for JS

I made an AsyncLock implementation due to a comment on Hacker News saying JavaScript was missing such a necessary idea. I honestly am not terribly familiar with Threaded programming and the concept of ...
1
vote
1answer
94 views

Acquiring multiple resource exclusively before processing using lock and monitor in JAVA

Here is my implementation of an all-or-wait-until-all kind of process. Each thread (kid) needs to guarantee it is the only thread processing the required resources (toys) at that moment. If some ...
1
vote
2answers
309 views

Parallel locking construct

I needed an object I can use to serialize specific operations in an otherwise parallel workflow. The specific use case I was solving for is request idempotency; a great example would be double-...
3
votes
1answer
84 views

Delete temp files on startup

I wrote some code for my question about deleting temp files that weren't deleted on exit before and would like to get some feedback if I forgot some details or got something wrong. ...
1
vote
1answer
75 views

canonical pattern for transactional library state manipulation

In golang I am finding that there is a definite pressure in the language itself and built-in libraries to do things in a canonical way. Please can someone critically look at these two ways I am ...
3
votes
0answers
47 views

Fast lock implementation using pipes only

For fun I wanted to create a lock implementation that was about as fast as one using futexes but that used used pipes instead and that queues waiters in user space instead of in-kernel. For the queue ...
5
votes
2answers
422 views

Locking in MySQL stored procedure for deduplication

Multiple upstream servers are sending notifications to a load-balanced django app. If all the upstream servers are working correctly, the app will always receive duplicates of these notifications (...
2
votes
1answer
91 views

Repeat operation if signal is received

I have a data synchronisation operation that is observing a database. This is a fairly key piece of code for the system, so I want to make sure I handle the concurrency correctly. The problem The ...
3
votes
1answer
315 views

Concurrency and locking in a chat server

I've never done concurrent programming before, but I've written one using go channels and RWMutex, but I'm not sure if my approach is idiomatic. I feel like it could all use channels (Maybe). The ...
2
votes
1answer
288 views

Redis lock implementation

Considering I'm not implementing distributed lock mechanism, is this code correct and clear? ...
1
vote
0answers
120 views

Locking for accumulating counter with statistics

I have an Accumulator class that uses AtomicLong to track some counters. I have methods to calculate statistics based on those ...
1
vote
1answer
74 views

Did I overuse / underuse threading locks in my custom list class?

I am writing a Python module in which two threads access one list. One thread adds 500 items to the list per second, and the other thread reads the list at an irregular interval. I want to make a ...
1
vote
0answers
81 views

Safe locking, replaced thread by task inside Job Manager

I replaced the thread by a task so there's no thread locked when there is no job to execute for hours. Now i'm not sure if the lock without an AutoResetEvent is lock safe when AllowParallelExcuteion ...
5
votes
0answers
116 views

Semaphore implementation by file locking in a bash script

This implementation is inspired by the POSIX functions sem_wait() and sem_post(). It tries to get rid of busy loops in the code ...
4
votes
1answer
2k views

C++ lock wrapper class around pointer

I have created a class which wraps pointers and behaves like a pointer would behave, minus a few cases. It is a lock wrapper class which simply locks before usage of the pointer and unlocks once the ...
5
votes
1answer
869 views

Concurrent byte array access in Java with different locking

I have one writer thread and 10 reader threads of a byte array. It is important to synchronize writes and reads over a "row" (16 bytes). There are a lot less locks than rows, e.g. in the current ...
2
votes
2answers
195 views

Thread-efficient nonce generations

I need to create unique nonces for cryptographic purposes in a library that I am writing. If the nonces ever fail to be unique, the consequences may be up to and including remote execution of ...
5
votes
2answers
178 views

Snoozy: A lazy reevaluation upon get

I would appreciate critique and comments in regards of thread-safety on a basic type I'm trying to create. In C#, the Lazy<T> type is initialized only once, ...
0
votes
1answer
68 views

How to avoid carrying around a lock with my variable when multiple threads instantiation in Python?

I created an application using multiple threads defined in multiple class files which read and write into a "shared variable" (a dictionary). To ensure thread-safety, I am using a Lock, and I pass it ...