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).

In Java, ReadWriteLock is a very abstract interface which provides functionality to synchronize between multiple readers and one exclusive writer.

It just assumes some structure that contains two locks. Serious problems with this interface are unlikely. If you ask something about it, probably you mean ReentrantReadWriteLock, the implementation.

Related tags:

96 questions
4
votes
0 answers

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 that updates the database (drops and loads a new…
sborpo
  • 928
  • 7
  • 15
4
votes
2 answers

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

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: use lazy_static::lazy_static; use…
Anders
  • 8,307
  • 9
  • 56
  • 88
4
votes
2 answers

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::list<> attemptList. Then child threads grab…
gofish
  • 347
  • 3
  • 10
4
votes
1 answer

Java: Difference between ReadWriteLock and ReentrantReadWriteLock

I have some data structure, in which I want to exclusively lock the access for writing, but to enable parallel access for reading. I made some searches and found out the classes ReadWriteLock and ReentrantReadWriteLock - which both supply a…
SomethingSomething
  • 11,491
  • 17
  • 68
  • 126
4
votes
1 answer

How to implement a reader/writer lock in C++14

I have a hash table data structure that I wish to make thread safe by use of a reader/writer lock (my read:write ratio is likely somewhere in the region of 100:1). I have been looking around for how to implement this lock using C++11 (such as the…
Ephemera
  • 8,672
  • 8
  • 44
  • 84
4
votes
5 answers

Is a read lock on a ReentrantReadWriteLock sufficient for concurrent reading of a RandomAccessFile

I'm writing something to handle concurrent read/write requests to a database file. ReentrantReadWriteLock looks like a good match. If all threads access a shared RandomAccessFile object, do I need to worry about the file pointer with concurrent…
Ed Mazur
  • 3,042
  • 3
  • 21
  • 21
3
votes
1 answer

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 tried using a vector of Arc. #[derive(Default, Debug,…
Kandah
  • 33
  • 4
3
votes
1 answer

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 { struct job *q_head; struct job *q_tail; …
yeshengm
  • 557
  • 5
  • 13
3
votes
2 answers

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: class ReadWriteLock { public: …
L-S
  • 107
  • 7
3
votes
1 answer

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 those calls are coming from, I can't guarantee…
Smashery
  • 57,848
  • 30
  • 97
  • 128
3
votes
1 answer

ReadWriteLock. Understanding upgrading from readLock to writeLock

Consider this JDK standard interface: public interface ReadWriteLock{ public Lock readLock(); public Lock writeLock(); } B. Goetz in Java Concurrency in practice mentioned upgrading from readLock to writeLock is deadlock-prone. If two…
user2953119
3
votes
1 answer

How do I deal with greedy write locking in MongoDB?

My question - is there a way to read and write to the MongoDB simultaneously? Or make MongoDB reader greedy? I have a web application that uses MongoDB for the database. In my application, I have a Serial Event that I am listening for. On this…
Lauren
  • 147
  • 1
  • 3
  • 10
2
votes
1 answer

Android contentprovider lock

Should I use a ReadWriteLock on the functions of the contentprovider? In the query of the contentprovider I do getReadableDatabase, then check if its open and do the query. But sometimes it crashes on DatabaseIsClosed exeption. This could be that an…
Ion Aalbers
  • 7,830
  • 3
  • 37
  • 50
2
votes
0 answers

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 of the read and write operations, and the…
Stefan
  • 969
  • 6
  • 9
2
votes
1 answer

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 can i trasfer the handle . i dont want to use a…
redkont
  • 337
  • 1
  • 2
  • 12