Questions tagged [readwritelock]

ReadWriteLock is a structure of the two locks. From these, one locks for reading (multiple threads can access, none can modify) and another for write access (only one thread can access and also modify at time).

Filter by
Sorted by
Tagged with
0 votes
0 answers
42 views

performance differences between shared_mutex.lock and shared_mutex.lock_shared?

The scenario is: I have two shared_mutex for two shared variable a b, to prevent deadlock, if thread A get mutex_a but cannot get mutex_b, thread B get shared_mutex_b but cannot get shared_mutex_a, ...
Xin_Wang's user avatar
0 votes
0 answers
25 views

Handle Hash Collison in Stripe Read Write lock

We are using stripe lock for one of our implementation. We take readlock on some final constant and a writelock on key. We noticed that we ran into a deadlock because hash code of two different keys ...
arun's user avatar
  • 398
0 votes
0 answers
152 views

Why do read locks and write locks handle expiration time differently in Redisson?

Here are the lock scripts of read lock and write lock in Redisson. lock script of read lock lock script of write lock As we can see from the script, if read lock is reentrant and lock again, the ...
chaos's user avatar
  • 1,359
1 vote
2 answers
925 views

How a process release a redis lock which was not owned by this process?

I tried to implement a simple read-preferred read-write lock using 2 mutexes (using redis.lock.Lock), like what is described in this link (https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock) In ...
Tuan Le PN's user avatar
0 votes
1 answer
203 views

Read/Write lock required when writing to a std::map<K, V> in a separate thread

I've implemented a systemd service in C++ that automatically starts when the system boots. The goal of this service is to acquire system resources and make them accessible via an API. One of these ...
Xershy's user avatar
  • 187
0 votes
1 answer
176 views

c++ double shared_lock freezes the program on windows

When I am learning shared_mutex in C++17, I find a weired problem. If I call shared_lock twice in one thread, and call unique_lock in another thread, then my program will freeze. Like this: std::mutex ...
user20011090's user avatar
0 votes
1 answer
220 views

Order Matching System Design : how to design an efficient and secure crypto account system

Context I am working in a crypto exchange company as backend engineer. Recently, we are facing a performance issue in our matching system. When user's order got match, system will deduct or add order'...
vicxu's user avatar
  • 1
0 votes
1 answer
210 views

Dispose ReaderWriterLockSlim after ExitWriterLock

I have a function to clean up some objects as well as the ReaderWriterLockSlim. But I need the ReaderWriterLockSlim to lock as writer lock to prevent the other thread read the data while I am doing ...
leuction's user avatar
  • 563
1 vote
0 answers
119 views

ReadWriteLock downgrading not working as expected

I am new to Redisson and tried to implement a ReadWriteLock downgrade but after doing the release of the writeLock, Redisson is not renewing the lock even when there is still a readlock and after 30 ...
elizalde1981's user avatar
0 votes
1 answer
1k views

How to read a variable without lock in Python threads?

I am using Python threading to do some jobs at the same time. I leave the main thread to perform task_A, and create one thread to perform task_B at the same time. Below is the simplified version of ...
SHM's user avatar
  • 61
0 votes
1 answer
324 views

Write locks have priority to access the critical region in a java readWrite lock? [closed]

I need writers threads to have priority to access critical region over readers threads, can I use the ReadWriteLock interface to do this?
Juan Gil's user avatar
0 votes
1 answer
53 views

Where could be any problems in the program and how i solve them with using lock() and unlock()?

The following piece of pseudo-code shows a typical reader / writer scenario: string document; string::size_type length = 0; write() { while (true) { string text = readFromKeyboard(); ...
LaPlace's user avatar
-1 votes
1 answer
129 views

Boost multithreading exception

I have a program like main.cpp #include <stdio.h> #include <boost/thread/shared_mutex.hpp> #include <boost/thread.hpp> class MutexClass { private: /* data */ boost::...
licha's user avatar
  • 1
2 votes
0 answers
136 views

Can ReadWrite lock perform worse than conventional locks?

From oracle: Whether or not a read-write lock will improve performance over the use of a mutual exclusion lock depends on the frequency that the data is read compared to being modified, the duration ...
Stefan's user avatar
  • 969
1 vote
1 answer
423 views

Write lock Ntag 424DNA using makeReadOnly() throwing failed error

Creating react native NFC read/write application using https://github.com/whitedogg13/react-native-nfc-manager ->with this plugin. But I was not able to write lock after writing a NDEF record to ...
AnAndHu S's user avatar
4 votes
0 answers
42 views

Locking a resource for update process (ReadWrite lock) In Container Enviroment

I have a python application that accesses a database (PostgreSQL) with a master data in order to search within it - done by a search threads (A 150 mb database). Once a day there is an update process ...
sborpo's user avatar
  • 928
4 votes
2 answers
1k views

Return a reference to a T inside a lazy static RwLock<Option<T>>?

I have a lazy static struct that I want to be able to set to some random value in the beginning of the execution of the program, and then get later. This little silly snippet can be used as an example:...
Anders's user avatar
  • 8,317
0 votes
1 answer
389 views

Can SRW Lock be used as a binary semaphore?

Slim Reader/Writer (SRW) Locks is a synchronization primitive in Windows, available starting from Windows Vista. Name and interface suggests that it should be used as non-timed shared non-recursive ...
Alex Guteniev's user avatar
2 votes
1 answer
1k views

sharing read-write lock between interprocess

I have two processes rwlock1(parent) and rwlock2(child) . i want to use read-writer lock between processes , i need to transfer pthread_rwlock_t mem_lock to child process, i have a simple code , how ...
redkont's user avatar
  • 337
-1 votes
1 answer
779 views

Java file lock for read and write with multiple processes [duplicate]

In my application multiple processes are trying access a file for read and write. Every application has a single thread. I need to make sure that no 2 processes are accessing the file at the same time....
Bagira's user avatar
  • 2,149
-1 votes
1 answer
134 views

Problem in implementing multiple threading for operations on a linked list

In the following code, I tried handling various linked list operations using multiple threads. Multiple linked lists can be supported and all functions are generic except I kept a few printf ...
user avatar
0 votes
1 answer
924 views

Is Windows' AcquireSRWLockExclusive recursive?

I need to use read-write lock, but I would also like to be sure that the lock is recursive in both read and write mode, so that calling function that uses it on the same thread doesn't lock. I found ...
Tomáš Zato's user avatar
  • 50.3k
3 votes
1 answer
1k views

How to create a vector of RwLock in rust?

I need to make a vector of struct. Each element of the vector have to be protected by a RwLock. Threads need to read and write in this vector ( thanks to RwLock ). How can I do that in Rust. I've ...
Kandah's user avatar
  • 33
4 votes
2 answers
7k views

C++ MultiThreading Mutex Locks Segmentation Fault

** This is for a college class, I am not actually trying to crack passwords ** Below is my source code, but essentially what I want to have happen is the parent process en queues passwords into an std:...
gofish's user avatar
  • 347
-3 votes
2 answers
422 views

Simple Read Write Lock

I find many read write Spin lock implementation over the internet are unnecessarily complex. I have written a simple read-write lock in c++. Could anybody tell me , if I am missing anything? int r =...
tekkk's user avatar
  • 334
1 vote
0 answers
119 views

How to replace a concurrently instance without losing data?

I have many threads who save the state and one thread that logs the state. I'd like to not lose data, which means to always log the latest state. The solution I have is to use a read-write lock when ...
AlikElzin-kilaka's user avatar
0 votes
1 answer
2k views

python multiprocessing read write lock

I have multiprocessing python code using multiprocessing.Lock. I would like to change it to have read-write lock instead of simple lock. I was looking for an implementation of it but the only multiple ...
Diana's user avatar
  • 86
1 vote
1 answer
360 views

Write-locked file sometimes can't find contents (when opening a pickled pandas DataFrame) - EOFError: Ran out of input

Here's my situation: I need to run 300 processes on a cluster (they are independent) that all add a portion of their data to the same DataFrame (they will also need to read the file before writing as ...
Marses's user avatar
  • 1,474
3 votes
1 answer
356 views

Safe removal of a node in a concurrent linked list

I'm currently reading the book APUE. When I read the chapter about pthread reader/writer-lock, I have a question about its implementation of concurrent queue using reader/writer-lock. struct queue { ...
yeshengm's user avatar
  • 557
0 votes
1 answer
52 views

correct usage of readwrite locks

I have a requirement which is as below : 1) A class which has all static methods and a static list. This list stores some objects on which I perform some operation. 2) Now this operation is called ...
Onki's user avatar
  • 1,889
5 votes
1 answer
1k views

Implementing write-preferring R/W lock

I have a mutex library, and am trying to implement a write-preferring lock. I am looking at this example: https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock I understand the read-preferring ...
user avatar
81 votes
2 answers
26k views

When or why should I use a Mutex over an RwLock?

When I read the documentations of Mutex and RwLock, the difference I see is the following: Mutex can have only one reader or writer at a time, RwLock can have one writer or multiple readers at a time....
Boiethios's user avatar
  • 38.7k
1 vote
1 answer
217 views

What's wrong with my usage of ReentrantReadWriteLock?

I have a trouble with ReentrantReadWriteLock. Thread hangs when I trying to wipe file. I have a scheduled read operation and eventual write operation(when user presses the button) which use one ...
chill appreciator's user avatar
1 vote
0 answers
184 views

implementing a c# read write lock where some reads produce writes

I have to implement some .Net code involving a shared resource accessed by different threads. In principle, this should be solved with a simple read write lock. However, my solution requires that some ...
Alberto Anguita's user avatar
0 votes
2 answers
924 views

Read lock while Writing

I need help in understanding the below code : private Predicate composedPredicate = null; public boolean evaluate(Task taskData) { boolean isReadLock = false; try{ rwl....
oberyn_nidhi's user avatar
0 votes
1 answer
1k views

How to Synchronize File operation using java? Synchronized or Lock?

I created a application for reading and writing to a remote location property file using JSCH library. I want to synchronize the write operation . This is my code , class WebApp{ private String ...
Ansar Samad's user avatar
0 votes
1 answer
568 views

ReadWriteLock writelock saturated

I have an issue with the Writer thread being starved without getting a lock. Please have a look at the following code. If I am trying to get the lock using tryLock() for the read lock, the writer ...
Vishnu Potukanuma's user avatar
0 votes
2 answers
2k views

Cassandra write lock

I'm doing a project where we use Cassandra and I've stumped at an optimisation point. We want to change the database structure considering that read actions are a pretty heavy load on Cassandra. ...
milan's user avatar
  • 1
1 vote
1 answer
1k views

Resolving Whoosh IndexingError: Writer is closed

Different from python whoosh IndexingError when interrupted, I've not interrupted any commits but the IndexingError occurs when creating a new index: import uuid import os from whoosh.index import ...
alvas's user avatar
  • 116k
1 vote
1 answer
2k views

Lockmode PESSIMISTIC_WRITE in criteria vs select for update

Is there any significant difference in performance in using PESSIMISTIC_WRITE as LockMode in hibernate criteria as an alternative for Select for update query. Use case involves following points: ...
Amit Pareek's user avatar
2 votes
1 answer
967 views

Are pthread read-write locks FIFO?

In the library pthread.h are pthread_rwlock_t FIFO? In the following example we have multiple threads. Imagine that every thread is guaranteed to run in order. // Thread 1 - does a write lock ...
Gary Holiday's user avatar
  • 3,317
3 votes
2 answers
703 views

How can I implement a C++ Reader-Writer lock using a single unlock method, which can be called be a reader or writer?

I'm working on a project, which requires the use of specific OS abstractions and I need to implement a reader-writer lock using their semaphore and mutex. I currently, have a setup in the format: ...
L-S's user avatar
  • 107
10 votes
3 answers
412 views

Documentation contradictions about ReentrantReadWriteLock. Does eventually write lock has priority over read lock or not in fair mode?

From ReentrantLock javadoc: Fair mode When constructed as fair, threads contend for entry using an approximately arrival-order policy. When the currently held lock is released either the ...
gstackoverflow's user avatar
0 votes
0 answers
36 views

non-fair ReentrantReadWriteLock write and read lock priorities [duplicate]

If I understand correct if I use fair mode read and write locks doesn't have priorities and all locks will be acquired on order of the requesting by other threads. After write request receiving - if ...
gstackoverflow's user avatar
3 votes
1 answer
428 views

TaskScheduler to always run on the same thread

I have some code using a ReaderWriterLockSlim. I acquire a write lock on it when a certain object is constructed, and release it when that object is disposed some time later. However, because of where ...
Smashery's user avatar
  • 58k
2 votes
1 answer
1k views

Swift pthread read/write lock taking a while to release the lock

I am trying to implement a read/write lock in Swift with the pthread API's and I have come across a strange issue. My implementation is largely based on the following with the addition of a timeout ...
Randy's user avatar
  • 2,270
1 vote
0 answers
36 views

Is there a structure for read or write_lock in a database?

Say I want to write (update) something that exists in many tables of my database like an EMPID, and I want to change all the EMPID from having 4 numbers to 5. How would you write this? Is it a ...
Luna's user avatar
  • 1
0 votes
1 answer
96 views

Java ReadWriteLock Reentrance

Hi i have read about the ReadWriteLock in Java but i am not sure that i have grasped the reentrance part of it. Here is two brief code examples using only one main thread to show reentrance public ...
user2133558's user avatar
8 votes
2 answers
2k views

Do I ever *not* want to use a read/write lock instead of a vanilla mutex?

When synchronizing access to a shared resource, is there ever a reason not to use a read/write lock instead of a vanilla mutex (which is basically just a write lock), besides the philosophical reason ...
adoug's user avatar
  • 83
0 votes
1 answer
157 views

ReadWriteLocks-(Non-reentrant) how it supports multiple readers to acquire read locks

I came across below non-reentrant implementation of ReadWriteLock in many tutorials. public class ReadWriteLock{ private int readers = 0; private int writers = 0; private int ...
Pintu's user avatar
  • 102