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).
86
questions
0
votes
0answers
13 views
Can I use Javas readwritelock to lock hibernate execute and find methods? H2 Database
I have a couple of DAOS that use either execute to change a table or find to show stuff from a table. I'm now trying to make it so the tables can't be changed when multiple people use the system and ...
-1
votes
1answer
50 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::...
2
votes
0answers
66 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 ...
1
vote
1answer
85 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 ...
0
votes
0answers
43 views
Use existing ngx_slab_pool_t to implement a interprocess read-write lock in nginx
According to ngx_shared_memory_add in src\core\ngx_cycle.c or Development guide - Shared memory, I know ngx_shm_zone_t is allocated in a private process, i.e. an handler to communicate with a shared ...
4
votes
0answers
22 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 ...
3
votes
2answers
191 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:...
0
votes
1answer
158 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 ...
1
vote
1answer
129 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 ...
-1
votes
1answer
195 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....
-1
votes
1answer
71 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 ...
0
votes
1answer
398 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 ...
3
votes
1answer
417 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 ...
2
votes
2answers
2k 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:...
-3
votes
1answer
196 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 =...
1
vote
0answers
77 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 ...
-2
votes
1answer
966 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 ...
1
vote
1answer
141 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 ...
3
votes
1answer
179 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 {
...
0
votes
1answer
46 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 ...
4
votes
1answer
572 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 ...
39
votes
1answer
7k 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 reader at a time.
...
1
vote
1answer
120 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 ...
0
votes
0answers
69 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 ...
0
votes
2answers
493 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....
0
votes
1answer
898 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 ...
0
votes
1answer
360 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 ...
0
votes
2answers
927 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.
I ...
1
vote
1answer
695 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 ...
1
vote
1answer
858 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:
...
2
votes
1answer
666 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
...
3
votes
2answers
495 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:
...
10
votes
3answers
341 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 ...
0
votes
0answers
34 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
...
3
votes
1answer
388 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 ...
1
vote
1answer
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 ...
1
vote
0answers
34 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 ...
0
votes
1answer
79 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 ...
3
votes
2answers
748 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 ...
0
votes
1answer
120 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 ...
4
votes
1answer
1k views
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 ...
0
votes
1answer
319 views
how to make boost upgrade_to_unique_lock + condition_variable work together?
I use a std::list to hold some string, one thread writes to the list and some other threads read from it(get the first and erase from the list). Here's the code:
std::list<string> list_;
boost:...
3
votes
1answer
1k views
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 ...
2
votes
1answer
218 views
Java Concurrency ReadWriteLock with my own timestamp
ReentrantReadWriteLock is perfect for read-write scenario based on timestamp programmatically at the time of reception.
PUT(KEY=1,VALUE=1)
PUT(KEY=1,VALUE=2)
GET(KEY=1)
PUT(KEY=1,VALUE=1)
...
Java ...
4
votes
1answer
2k views
Upgrading read lock to write lock without releasing the first in C++11?
I know it's possible using boost::UpgradeLockable in C++14.
Is there anything similar for C++11?
0
votes
1answer
260 views
pthread read-write lock indefinite behaviour
I came across a unexpected results in test for pthread read-write lock.
the following is my code.
#include <iostream>
#include <thread>
#include <pthread.h>
//locks declaration
...
4
votes
1answer
5k views
Synchronized vs ReadWriteLock performance
I try to prove that synchronized is slower when there are many readers and only some writers. Somehow I proved the opposite.
The RW example, time of execution is 313 ms:
package ...
3
votes
3answers
2k views
Why to use a readlock?
I read that a write lock is exclusive and a read lock is shared , so a piece of code which in readlock anyway can be accessed by multiple threads . What if no read lock is acquired by the threads in ...
1
vote
1answer
628 views
How to implement A Cache by using ReadWriteLock in java?
My main question is "Do I really need recheck the value in the following code"?
The following code describes how to implement a cache by using ReadWriteLock.
public class ReadWriteLockCache {
...
2
votes
2answers
631 views
Read a file in a while loop line-by-line while another function updates it
I am reading a file in a while loop from start to end:
FILE *file;
file = fopen(path_to_file), "r");
char *line = NULL;
size_t len = 0;
while (getline(&line, &len, file) > 0) {
...